serve-handler
serve-handler copied to clipboard
Using glob with capture for rewrites
Here's the closest example to what I want to do for rewrites that I found:
{
"rewrites": [
{ "source": "/projects/:id/edit", "destination": "/edit-project-:id.html" },
]
}
What I really want to do is have
- /pages/** all handled by /index.html
- /tags/** all handled by /index.html
But I don't want to rewrite the url. I just want to have all requests be handled by my react app, the entry point for which is index.html.
What I find now is that if I go directly to a page (let's say /pages/foo), or do a forced refresh of that page, react doesn't load/route properly and returns a 404.
So what rules do I need to have all requests under the specific paths /pages/** and /tags/** all handled by /index.html but without changing the URL?
a few quick thoughts:
- a redirect would simplify things
- a rewrite will load the content of your "destination" file at the requested URL
- which will break relative links..
- so make sure the "destination" file only uses absolute paths (ie: begin with
/)