vercel / serve-handler

The foundation of `serve`
https://npmjs.com/serve-handler
MIT License
572 stars 98 forks source link

Rewrite not working in v14.2.0 #200

Open Matthematic opened 1 year ago

Matthematic commented 1 year ago

Hello, I am using create-react-app to generate my build folder for my SPA and I want to serve a single, standalone html file called health.html that is also in the public folder, like so: image

A request to localhost:3000/health should serve health.html, and any other requests should serve index.html. For some reason I cannot get this to work at all. From the docs, the following contents of serve.json seems like it is correct, but all requests to /health still redirect to index.html.

{
    "rewrites": [
      { "source": "/health", "destination": "/health.html" }
    ]
}

For reference, I am using this command:

serve -s build

What am I doing wrong?

JenLyndle commented 7 months ago

I am having a similar issue. I have the serve.json in dist folder and serving it and my rewrite rules do not seem to work. did you find a solution @Matthematic ?

Matthematic commented 7 months ago

I am having a similar issue. I have the serve.json in dist folder and serving it and my rewrite rules do not seem to work. did you find a solution @Matthematic ?

This was nearly a year ago and the contract for that job was fulfilled so I no longer have access to the code, but from memory I believe I switched the project over to vite instead of create-react-app since the latter is no longer maintained. This can be done easily with vite plugins.