Closed hauptmedia closed 2 years ago
We think this should be implemented at the application layer.
You should be very easily to implement the following logics within the on('request') callback:
/api
, then $response->sendfile(__DIR__ . '/index.html')
Hi,
i want to discuss how we could implement a solution for the following feature:
If i deploy a single page application (like vue, react, etc) I want to redirect all non php routes routes to a single index.html page.
E.g. if the single page application generates a path /entity/$id/blah it should be mapped to /index.html internally to deliver the single page application. The single page application will then take care the path and route to the corresponding sub page within the single page application.
Currently the only way (known to me) to implement this is in Openswoole is:
Deliver index.html via http_index_files (will work for paths like / or /entity but not work for /entity/$id/blah)
Implement a custom 404 Handler in PHP which will deliver the index.html if path could not be found
A more elegant solution would be:
Possibility to define path prefixes that should be mapped to PHP, all other requests go to static handler (basically the opposite of static_handler_locations). This way i could for example only map /api to PHP space.
Some kind of "catch all" mechanic which allows me to map files to a single index.html internally. This could be done with internal url rewrites (i think it's too complex) or a custom configuration option, or perhaps a static file override for 404 error pages (but this might cause confusion, because it should be also configurable if the server should deliver a 200 or 404 in this case).
What do you think? Or am I missing something here?
Thank you for your time,
Julian