mpetrunic / fastify-sse-v2

Provide Server-Sent Events to Fastify

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No way to pass in headers or CORs options

jdgriffith opened this issue · comments

Thanks for the plugin! My team is attempting to implement this for our needs using the Nestjs framework. It works pretty well accept for the matter of CORs in the browser. It would be great if you could pass in an options object for customizing headers, etc. For our needs, I think we have a workaround but would be nice if we could modify this at a global level.

Thanks!

We noticed that in our project as well. We used suggestion by fastify team to use response stream directly which means setting headers on reply object gets ignored.
You can put cors headers with:
reply.raw.setHeader("Access-Control-Allow-Origin","*");

https://github.com/NodeFactoryIo/fastify-sse-v2/blob/master/src/plugin.ts#L11

Let me know if this helps?
I will look into appying headers set on reply object or allowing map param with headers.

commented

Just ran into this myself.
Was quite confusing as I already had the fastify-cors package installed and configured.