fix(serve): content can be served from output_path (#2398)

This fixes a bug introduced in https://github.com/getzola/zola/pull/2258

The issue arose when `output_path` was relative. The request being
served would be canonicalized and this would be a string. So, for
example, if you were serving content from `public` the code
[right after](38199c1255/src/cmd/serve.rs (L144-L147))
the canonicalization checking if
`root.starts_with(original_root)` would always return `false` since
an absolute path, `/some/path/to/content` would never start with a
string like `public`.
This commit is contained in:
Stan Rozenraukh 2024-01-07 14:37:33 -05:00 committed by Vincent Prouillet
parent a01e36bd86
commit 13a4d9d9cf

View file

@ -461,9 +461,9 @@ pub fn serve(
let ws_address = format!("{}:{}", interface, ws_port.unwrap());
let output_path = site.output_path.clone();
// output path is going to need to be moved later on, so clone it for the
// http closure to avoid contention.
let static_root = output_path.clone();
// static_root needs to be canonicalized because we do the same for the http server.
let static_root = std::fs::canonicalize(&output_path).unwrap();
let broadcaster = {
thread::spawn(move || {
let addr = address.parse().unwrap();