serve icon indicating copy to clipboard operation
serve copied to clipboard

Using `--single` option, lose reference to js script when route is multiple levels deep

Open samrae7 opened this issue 8 years ago • 2 comments

I think my issue is similar to https://github.com/zeit/serve/issues/70 except I can't fix it by adding a slash to my url as the poster there can

I wants to serve index.html, (which has a script tag point to a bundle.js in the same folder) for every route, including multi-nested routes ( eg. localhost: 5000/foo/bar/foobar)

So I am serving with serve -s and it works but not when I get more than one level deep. Eg. http://localhost:5000/bar works but not http://localhost:5000/bar/foo.

I get error Uncaught SyntaxError: Unexpected token < in the console, because the index.html file is being served instead of the bundle.js.

That kind of makes sense because the single option is supposed to serve index.html for everything it can't find, but my question is how to make it be able to find the bundle.js from the index.html, no matter what url path we are on.

Please see this simple example repo to reproduce: https://github.com/samrae7/serve-repro

Is there a way to achieve what I want? e.g. Is there an obvious fix in the path I should use in the <script> tag in index.html?

samrae7 avatar Sep 16 '18 21:09 samrae7

Oh dear I just realised that if I change this <script src="bundle.js"></script> to <script src="/bundle.js"></script> it fixes it.

samrae7 avatar Sep 16 '18 21:09 samrae7

Encountered this issue also, but I don't prefixing / solution didn't helped me

dvakatsiienko avatar Oct 19 '18 10:10 dvakatsiienko