openapi-backend
openapi-backend copied to clipboard
Handler for preflight requests with correct access-control-allow-methods
Two things are needed:
- A way to handle all preflight (
OPTIONS) requests. Right now they are likely handled by the notFound handler. - A way to get the allowed methods for any api path.
Expectation:
// handle all OPTIONS requests
api.register('preflightHandler', (c) => {
const headers = {
"access-control-allow-methods": c.api.getAllowedMethods(c),
"access-control-allow-headers": "Authorization",
"access-control-allow-origins": c.request.headers.origin,
"access-control-allow-credentials": "true",
};
// return empty body for OPTIONS
return replyJSON(null, { headers });
})