sstur / nbit

A zero-dependency, strongly-typed web framework for Bun, Node and Cloudflare workers
65 stars 4 forks source link

How to set cors globally? #18

Open svnty opened 7 months ago

svnty commented 7 months ago

Hello,

How can I set cors globally? In express it would be

app.use(cors());

I have nbit working as such

        return Response.json({ hello: 'world' }, {
          headers: {
            "Access-Control-Allow-Methods": "GET, HEAD, POST, OPTIONS",
            "Access-Control-Allow-Headers": "Content-Type, Accept",
            "Access-Control-Allow-Origin": "https://medicamina.us"
          });

but I don't want to copy paste this boilerplate headers object everywhere, can I set it once and forget about it like app.use(cors())?

sstur commented 7 months ago

Currently this isn't possible, but I've implemented a proof of concept in #19, if you have any thoughts.