Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.html is stripped from URL #732

Open
trusktr opened this issue Oct 1, 2022 · 9 comments
Open

.html is stripped from URL #732

trusktr opened this issue Oct 1, 2022 · 9 comments

Comments

@trusktr
Copy link

trusktr commented Oct 1, 2022

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

@mdtausifiqbal
Copy link

mdtausifiqbal commented Oct 20, 2022

Same Issue

When visiting localhost:3000/foo.html?query=bar serve strips the .html?query=bar

Library version is 14.0.1

@mdtausifiqbal
Copy link

@trusktr I found that this issue belongs to the core of serve that is serve-handler

We should create an Issue in that repository

@trusktr
Copy link
Author

trusktr commented Jan 13, 2023

new issue: vercel/serve-handler#178

@thorsent
Copy link

I think cleanUrls: false avoids this behavior.

@Glidias
Copy link

Glidias commented Apr 12, 2023

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...

@bramus
Copy link

bramus commented Apr 13, 2023

@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

@Glidias
Copy link

Glidias commented Apr 14, 2023

@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.

@ADTC
Copy link

ADTC commented May 16, 2023

@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.

@kungfooman
Copy link

A config file in src seems also awkward... anyway, @bramus answer solved it for me, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants