webiny-js
webiny-js copied to clipboard
Ability to customize response headers
Is your feature request related to a problem? Please describe.
In /graphql
and /cms
api set "Access-Control-Allow-Headers"
response header as "*"
which is ignored in some old browsers (in my test case: iphone 6, safari < 13), and would cause error in browser and only a blank page is shown.
Related stackoverflow: https://stackoverflow.com/questions/13146892/cors-access-control-allow-headers-wildcard-being-ignored https://caniuse.com/mdn-http_headers_access-control-allow-headers_wildcard
Describe the feature's behavior.
Add params in fastify createHandler
to pass headers
to override the default headers.
Actually, setting the Access-Control-Allow-Headers
as explicit values would be enough for my case.
Describe alternatives you've considered.
No response
or exposing the reply
to Context
like request
in fastify preParsing
hook, then we can set the headers by reply.headers(...)
.
https://github.com/webiny/webiny-js/blob/0af7ac294c5843709e894af9ce8e1db153a4c880/packages/handler/src/fastify.ts#L243-L249
Hi @taifok
We could possibly add some lifecycle hooks (or something similar) so you can add your stuff when you need to.
Exposing reply
to the Context
would not help because context plugins are initialized after the onRequest
, where we are setting the default headers (see Fastify Lifecycle docs) - it would be too late for OPTIONS request.