2026-02-25 22:54:49 +01:00

20 lines
529 B
TypeScript

import type { Context, Next } from 'hono';
export function createCorsMiddleware(allowedOrigin: string) {
return async (c: Context, next: Next) => {
const origin = c.req.header('Origin');
if (origin === allowedOrigin) {
c.header('Access-Control-Allow-Origin', allowedOrigin);
c.header('Access-Control-Allow-Methods', 'POST, OPTIONS');
c.header('Access-Control-Allow-Headers', 'Content-Type');
}
if (c.req.method === 'OPTIONS') {
return c.text('', 204);
}
await next();
};
}