From cc5d4761e3f775138ff4b69b9f84c515feedc6da Mon Sep 17 00:00:00 2001 From: "Kay ( Andrew )" Date: Wed, 30 Oct 2024 23:52:32 +0700 Subject: [PATCH] feat: add cors --- src/app.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/app.ts b/src/app.ts index 4f378c2..60d181c 100644 --- a/src/app.ts +++ b/src/app.ts @@ -6,10 +6,17 @@ const swaggerJsDoc = require('swagger-jsdoc'); const app = express(); const port = process.env.PORT || 3001; -app.use(cors()); + +const allowedOrigins = ['http://localhost:3000', 'https://buildlink.vercel.app']; app.use(cors({ - origin: 'http://localhost:3000' + origin: function (origin, callback) { + if (!origin || allowedOrigins.includes(origin)) { + callback(null, true); + } else { + callback(new Error('Not allowed by CORS')); + } + } })); const options = {