From 722755b5e1efdd60808bfe9895687ae766a2582f Mon Sep 17 00:00:00 2001 From: SDE-ADNAN Date: Fri, 29 Dec 2023 17:39:01 +0530 Subject: [PATCH] Update CORS configuration --- app.ts | 16 ++-------------- dist/app.js | 16 ++-------------- 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/app.ts b/app.ts index 04b5a4f..e7be40e 100644 --- a/app.ts +++ b/app.ts @@ -21,22 +21,10 @@ dotenv.config({ path: "./ENV/config.env" }) -// app.use(cors({ -// origin: ['https://adnans-react-typescript-todo.netlify.app'], // Replace with your frontend domain -// methods: 'GET,HEAD,PUT,PATCH,POST,DELETE', -// })); -const allowedOrigins:String[] = ['https://adnans-react-typescript-todo.netlify.app','']; - app.use(cors({ - origin: function (origin: string | undefined, callback) { - // Check if the request origin is allowed - if (allowedOrigins.includes(origin as string)) { - callback(null, true); // Allow the request - } else { - callback(new Error('Not allowed by CORS')); // Block the request - } - }, + origin: '*', // Replace with your frontend domain methods: 'GET,HEAD,PUT,PATCH,POST,DELETE', + credentials:true })); app.use(session({ diff --git a/dist/app.js b/dist/app.js index 5ec43b8..3c1c1de 100644 --- a/dist/app.js +++ b/dist/app.js @@ -21,22 +21,10 @@ const app = (0, express_1.default)(); dotenv_1.default.config({ path: "./ENV/config.env" }); -// app.use(cors({ -// origin: ['https://adnans-react-typescript-todo.netlify.app'], // Replace with your frontend domain -// methods: 'GET,HEAD,PUT,PATCH,POST,DELETE', -// })); -const allowedOrigins = ['https://adnans-react-typescript-todo.netlify.app', '']; app.use((0, cors_1.default)({ - origin: function (origin, callback) { - // Check if the request origin is allowed - if (allowedOrigins.includes(origin)) { - callback(null, true); // Allow the request - } - else { - callback(new Error('Not allowed by CORS')); // Block the request - } - }, + origin: '*', methods: 'GET,HEAD,PUT,PATCH,POST,DELETE', + credentials: true })); app.use((0, express_session_1.default)({ secret: 'your-secret-key',