preactjs / wmr

👩‍🚀 The tiny all-in-one development tool for modern web apps.
https://wmr.dev/
MIT License
4.93k stars 110 forks source link

Sending 404 status code when the routes don't match #799

Open sidvenu opened 3 years ago

sidvenu commented 3 years ago

Is your feature request related to a problem? Please describe. I observe router sends 200 status code when no routes match.

Describe the solution you'd like Allow us to send status codes based on the path.

Describe alternatives you've considered Sending 404s in the server (apache/nginx) layer, but that gets complicated as we have a lot of routes.

Additional context React Router has the ability to send status codes: https://stackoverflow.com/questions/36052604/how-to-let-react-router-respond-with-404-status-code.

I've also opened a similar issue in preactjs/preact-router: https://github.com/preactjs/preact-router/issues/402.

JoviDeCroock commented 3 years ago

What are you using as a serving mechanism as from client-side code it's not possible to set a server-side response code, as the stackoverflow you linked alludes to, you set this property to catch this in your serving layer.

developit commented 2 years ago

I left a solution for the render-to-string piece over on your preact-router issue. As @JoviDeCroock mentioned, WMR doesn't provide an SSR runtime (currently), so status codes are entirely up to your server (apache/nginx) to determine.