No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
Asked
Active
Viewed 65 times
0
georgeawg
- 48,608
- 13
- 72
- 95
Aakash Jaj
- 1
- 1
1 Answers
0
Install cors module add the following code:
const whitelist = ['http://localhost:5000'];
const corsOptions = {
origin (origin, callback) {
if (whitelist.indexOf(origin) !== -1 || !origin) {
callback(null, true);
} else {
callback(new Error('Not allowed by CORS'));
}
}
};
app.options('*', cors()); // CORS pre-flight
app.use(cors(corsOptions));
See the whitelist array. Add url here which you want to whitelist.
For example: add google.com to the array.
Shihab
- 2,641
- 3
- 21
- 29
-
I have already added headers in my app.js file. It is working fine, when I am switching from 4200 to 3000 port. But when trying to logging in with google getting above error – Aakash Jaj Oct 28 '19 at 12:52