feat(api): handle OPTIONS requests (#51610)

This commit is contained in:
Oliver Eyton-Williams
2023-09-19 23:45:51 +02:00
committed by GitHub
parent 5cb22dca84
commit c1bc0d3f39

View File

@@ -15,6 +15,10 @@ const allowedOrigins = [
];
const cors: FastifyPluginCallback = (fastify, _options, done) => {
fastify.options('*', (_req, reply) => {
void reply.send();
});
fastify.addHook('onRequest', async (req, reply) => {
const origin = req.headers.origin;
if (origin && allowedOrigins.includes(origin)) {