-
Notifications
You must be signed in to change notification settings - Fork 40
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
How to handle 404 requests that fallback into index.html but the route doesn't exists? #139
Comments
Hi @odahcam, basically you have two ways of handling this. If you are using client-side routing then you can just catch it and render 404 page but I guess you would not ask if you were using that. Second solution is to have a middleware that checks request url and sends 404 response if the path should not be available. |
I made both, thanks! It would be cool if the library had something built-in to help us handle 404. Just some opinionated list of interface that users could use to setup known routes on the root level of the app so ViteExpress automatically catches them and also adds a bypass for the files in the |
I think it is a good idea to have that kind of hook somehow available. If you are still willing to propose some solution I'd be happy to help with it, if not I understand that. I think having some config value (like a regex pattern) that you can specify to tell vite-express which front-end paths are valid + a hook that let's you validate them on the fly would be the perfect solution for you problem, if I understand that correctly. Let me know what you think! |
I like that proposed solution. In my case, I'm not using client-side routing at all, so I would prefer to turn off serving index.html for unknown paths entirely. |
I'm facing this issue right now any requests made to my server that are not captured by any mapped routes result in a html being returned to the client instead of a desired 404..
The text was updated successfully, but these errors were encountered: