Skip to content

Commit

Permalink
Update CORS configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
SDE-ADNAN committed Dec 29, 2023
1 parent 51fb142 commit 722755b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 28 deletions.
16 changes: 2 additions & 14 deletions app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
16 changes: 2 additions & 14 deletions dist/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 722755b

Please sign in to comment.