I am new to implementing CORS(enabling it for everyone) in a Node/Express application. I have found a snippet of code in app.js which is mentioned below:
const express = require('express');
const corsOptions = {
origin: '*',
};
const app = express();
app.use(cors(corsOptions));
app.options('*', cors(corsOptions));
app.listen(config.PORT);
I found the last two lines of code to be redundant. I am not sure as I am unable to test the CORS right now due to limited knowledge/understanding and resources on running Node/Express project.
Is it sufficient if we mention either app.use(cors(corsOptions)); or
app.options('*', cors(corsOptions));?
If Yes, is there a difference in their implementation?
If No, how does each line of code configure the Express Application?