serve html files without needing to write the .html extension (GET /thing is will return /thing.html if it exists)
This commit is contained in:
parent
6f0484f26b
commit
59ab02b472
1 changed files with 4 additions and 3 deletions
|
@ -137,9 +137,10 @@ fn get_file(request: &Request) -> Option<(Content, bool)> {
|
||||||
|
|
||||||
let current_dir = env::current_dir().unwrap();
|
let current_dir = env::current_dir().unwrap();
|
||||||
|
|
||||||
let path = current_dir
|
let request_path = request.path.strip_prefix('/')?;
|
||||||
.join(request.path.strip_prefix('/')?)
|
let request_path_with_ext = format!("{request_path}.html");
|
||||||
.canonicalize()
|
let path = fs::canonicalize(current_dir.join(request_path))
|
||||||
|
.or_else(|_| fs::canonicalize(current_dir.join(request_path_with_ext)))
|
||||||
.ok()?;
|
.ok()?;
|
||||||
|
|
||||||
if path
|
if path
|
||||||
|
|
Loading…
Reference in a new issue