Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Express.js response to Angular CORS Error

Tags:

angular

I want Express server side redirect angular page.
I run express at localhost:3000
angular at localhost:4200
when Express redirect to Angular localhost:4200
I always get error

Failed to load http://localhost:4200/login: Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response.


how to let angular accept cors response?

like image 508
luk Avatar asked Feb 03 '26 15:02

luk


1 Answers

Install cors package in your server-side express code

npm install --save cors

Use that in your server.js or app.js file where you implement all logic of express.js

const cors = require('cors');
app.use(cors());

It enables the cross-origin functionality, where you can access the request from another domain

like image 143
bajran Avatar answered Feb 06 '26 07:02

bajran