`.html` is stripped from URL
trusktr opened this issue · 9 comments
Description
When visiting localhost:3000/foo.html
, serve
strips the .html
so it becomes localhost:3000/foo
.
Library version
14.0.1
Node version
v16.13.2
Same Issue
When visiting localhost:3000/foo.html?query=bar
serve strips the .html?query=bar
Library version is 14.0.1
@trusktr I found that this issue belongs to the core of serve
that is serve-handler
We should create an Issue in that repository
new issue: vercel/serve-handler#178
I think cleanUrls: false avoids this behavior.
I tried to run this from serve.json file with the CLI command, but doesn't appear to have any effect.
{
"cleanUrls": false
}
hmm, not sure why or issit just me...
@Glidias I got it working by with this command:
serve src --config ../.serve.json
(serve
expects the JSON file in the src
dir, but I’ve got it in the root of the project repo so that’s why I needed to prepend ../
to the path)
and this .serve.json
{
"cleanUrls": false,
"redirects": [{ "source": "/", "destination": "/index.html", "type": 301 }]
}
However, I’ve noticed thatserve
is extremely unreliable with a config like this and would not serve some .html files, returning a 404 for them, even though if they do exist. Appending a querystring to the URLs would serve those files just fine, but that’s a hacky workaround.
In the end I turned out ditching serve
in favor of http-server
which does play nice with plain html files.
http-server src -p 3000 -d false --no-dotfiles
@bramus
I actually had the serve.json file at the root of the serving directory, so i thought it should had worked. However, I got it to work after changing the port setting and also another person had it worked fine. I confirmed this was likely because of browser cache due to cached 301 redirects.
@bramus Thanks. I thought this serve
utility is a simple HTTP server, but it has the hidden "feature" of rewriting paths to .html
files to remove the extension. It also rewrites paths ending in /
to not end in the slash. Honestly this should have been off by default, or at least easy to turn off via a command line configuration.
I'm ditching it in favor of http-server
as well, although its default 404 handling is out of whack.
A config file in src
seems also awkward... anyway, @bramus answer solved it for me, thank you!