Skip to content

Commit

Permalink
CORS 3
Browse files Browse the repository at this point in the history
  • Loading branch information
NolaDodd committed Jun 6, 2024
1 parent 315d4cb commit dccb24c
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions back-end/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,27 @@ const tablesRouter = require("./tables/tables.router")

const app = express();

var corsOptions = function(req, res, next){
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
res.header('Access-Control-Allow-Headers',
'Content-Type, Authorization, Content-Length, X-Requested-With');
next();
}

app.use(corsOptions);
// var corsOptions = function(req, res, next){
// res.header('Access-Control-Allow-Origin', req.headers.origin);
// res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
// res.header('Access-Control-Allow-Headers',
// 'Content-Type, Authorization, Content-Length, X-Requested-With');
// next();
// }

let corsOptions = {
origin : ['*', 'http://localhost:3000'],
}

app.use(cors(corsOptions))

// let allowedOrigins = ["http://ServerA:3000", "http://ServerB:3000"]
// let origin = req.headers.origin;
// if (allowedOrigins.includes(origin)) {
// res.header("Access-Control-Allow-Origin", origin); // restrict it to the required domain
// }

// app.use(corsOptions);

app.use(express.json());

Expand Down

0 comments on commit dccb24c

Please sign in to comment.