r/purescript • u/DeepDay6 • Jun 24 '24
HTTPurple - proxy request, modify response, serve static files?
I'm just considering a rewrite of a webapp-server from Express.js to HTTPurple. The server does the following things:
Manages user sessions and injects user auth to all requests (to resolve an issue with opening protected raw files in new tabs, which is probably a terrible idea that needs rework anyways)
Proxies paths starting with
/apito backend serversInterprets other paths as paths to static files and serves them, if they exist
Finally serves
index.htmlif paths don't match anything
All other routing is done in the SPA.
Why do I want to rewrite the server? There is a very fine-grained role-based authorization scheme managed by the backend. For UX-reasons, some backend responses contain a permission object with some requests (e.t. GET /api/entities/ returns { data: ..., permissions: { create: true } }.
Setting up accounts for all possible combinations of permissions is tedious, and for some combinations/new functionality, roles don't even exist yet, so I would like to inject permissions to (some) /api/... requets after they return from being proxied to the backend. Express' imperative handler will not let me access the responses after a handler has matched, but with pure functions this should be trivial.
So, are my use cases supported/possible with HTTPurple? Any suggestions?
1
u/amarrindustrial Oct 24 '24 edited Oct 24 '24
Did you find a way to serve static files?
Upd: https://github.com/sigma-andex/purescript-httpurple/blob/main/docs/Examples/AsyncResponse/Main.purs plus manually setting headers should do the job.
FWIW, I can't find how to do websockets with httpurple.