@starscream/routewise-cors
v0.1.0
Published
A fork of `@fastify/cors` that allows changing cors options easily on a per-scope or per-route basis.
Downloads
39
Readme
@starscream/routewise-cors
A fork of @fastify/cors that allows changing cors options easily on a per-scope or per-route basis.
You register this plugin once, and then within any scopes you want, you can set cors options, or override parent scope's cors options. You can also set CORS options or overrides on individual routes.
Works by always being ambiently registered, and tracking what the current options are throughout the Fastify plugin encapsulation tree. When a new route is added, the right CORS options for that route are resolved, and a parallel OPTIONS route is registered for that route that serves those options.
Differences from @fastify/cors
@fastify/corscan only be registered once per encapsulation scope, so you can't override it lower down@fastify/corsmust be given all the options when it is registered@fastify/corsapplies by default to all routes in a scope, and then allows disabling CORS for individual routes, but not adjusting options for individual routes, whereas we want the opposite for Gadget apps, where CORS is off by default and then you can opt in on a route-by-route or scope-by-scope basis.
Because of the above, @fastify/cors is hard to include by default in Starscream in a "sitting waiting for you to need it" mode, whereas @starscream/routewise-cors can be exactly that.
