From d4a7053c2933f67cb28bbdeb76856b60ea2f08aa Mon Sep 17 00:00:00 2001 From: AltSumpreme Date: Sun, 2 Feb 2025 15:20:48 +0530 Subject: [PATCH] feat:added cors middleware --- src/index.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 73e28cf..158368e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ import { serve } from "@hono/node-server"; import { OpenAPIHono } from "@hono/zod-openapi"; import { swaggerUI } from "@hono/swagger-ui"; - +import { cors } from "hono/cors"; import authRouter from "./routes/auth/index.js"; import userRouter from "./routes/user/index.js"; import teamRouter from "./routes/teams/index.js"; @@ -17,6 +17,12 @@ app.openAPIRegistry.registerComponent("securitySchemes", "Bearer", { scheme: "bearer", bearerFormat: "JWT", }); +app.use("*", (c, next) => { + const corsMiddleware = cors({ + origin: process.env.ALLOWED_ORIGINS?.split(",") || [], + }); + return corsMiddleware(c, next); +}); app.route("/auth", authRouter);