Skip to content

Commit

Permalink
enabled cors
Browse files Browse the repository at this point in the history
  • Loading branch information
AishwaryVishwakarma committed Feb 9, 2024
1 parent e6823e8 commit a423efe
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions server/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const express = require('express');
const mongoose = require('mongoose');
const app = express();
// const cors = require('cors');
const cors = require('cors');
const dotenv = require('dotenv');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
Expand All @@ -23,26 +23,26 @@ app.use(express.json());
// })
// );

// var allowedOrigins = [
// 'http://localhost:3000',
// 'https://netflix-five-zeta.vercel.app/',
// ];
var allowedOrigins = [
'http://localhost:3000',
'https://netflix-five-zeta.vercel.app',
];

// app.use(
// cors({
// origin: function (origin, callback) {
// // allow requests with no origin
// // (like mobile apps or curl requests)
// // if(!origin) return callback(null, true);
// if (allowedOrigins.indexOf(origin) === -1) {
// var msg =
// 'The CORS policy for this site does not allow access from the specified Origin.';
// return callback(new Error(msg), false);
// }
// return callback(null, true);
// },
// })
// );
app.use(
cors({
origin: function (origin, callback) {
// allow requests with no origin
// (like mobile apps or curl requests)
// if(!origin) return callback(null, true);
if (allowedOrigins.indexOf(origin) === -1) {
var msg =
'The CORS policy for this site does not allow access from the specified Origin.';
return callback(new Error(msg), false);
}
return callback(null, true);
},
})
);

app.use(cookieParser());
app.use(bodyParser.urlencoded({extended: true}));
Expand Down

0 comments on commit a423efe

Please sign in to comment.