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

npm run build under nginx routing not working. #144

Closed
sinistra opened this issue Jun 7, 2020 · 5 comments
Closed

npm run build under nginx routing not working. #144

sinistra opened this issue Jun 7, 2020 · 5 comments

Comments

@sinistra
Copy link

sinistra commented Jun 7, 2020

I have approx 6 routes in a spa app.
svelte-routing works perfectly with npm run dev.

if I build with npm run build and then run the app inside an nginx docker container, routes do not work.
eg. 'http://localhost:8080/products' and press enter ... "404 Not Found ... nginx/1.17.7"

does anyone have any ideas on where to look for the problem?

@dydx-git
Copy link

Yeah, I have the same issue. Did you manage to solve this?

@sinistra
Copy link
Author

sinistra commented Jun 21, 2020

no response here, so refactored using page.js.

@MrSrsen
Copy link

MrSrsen commented Jul 17, 2020

If I understand it correctly npm run build do not generate physical files in /public so nginx is trying to find non existing physical file and fails.

If you want your SPA to work properly you must config your nginx to redirect all calls (with path intact) to index.html file. This fixed the same issues with exported Svelte/Sapper application that I was working on.

I don't know how to configure nginx but for Apache my working .htaccess is:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.html?q=$1 [L,QSA]

Or use hash routing.

@EmilTholin
Copy link
Owner

Hi @sinistra!

@MrSrsen is right on the money. You must either configure nginx to serve your index.html file for every route, or use SSR like in the example in this repository.

@kevin4dhd
Copy link

any example only nginx?

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

5 participants