pearofducks / rollup-plugin-dev

development server for rollup with additional logging and options
MIT License
61 stars 9 forks source link

404s from backend proxy shouldn't fallback to spa #9

Closed abdatta closed 3 years ago

abdatta commented 3 years ago

The title says it all! When we get a 404 response from a proxied backend, it should not fall back to index.html even when spa: true.

A backend server often returns a 404 response when it fails to find some resource. This response is often used by an SPA frontend to show the info in a nice format. We don't want such a request to fallback to an HTML file (with 200 response).

It'll be very helpful if you can either make it the default behaviour to not to fallback from proxied responses, or maybe add a new flag that can turn on this ability.

Thank you for this very helpful plugin!

pearofducks commented 3 years ago

This sounds like your accepts header isn't set properly. The SPA middleware checks for accepts of html, and only will send a response when that's true.

If you set your accepts header to JSON (application/json), this shouldn't happen.