3

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?

David R
  • 14,711
  • 7
  • 54
  • 72
luk
  • 75
  • 4
  • 15

1 Answers1

4

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

bajran
  • 1,433
  • 14
  • 23
  • but I want to send response to angular not send request to express is this server side problen? – luk Aug 09 '18 at 07:09
  • @luk https://stackoverflow.com/questions/32500073/request-header-field-access-control-allow-headers-is-not-allowed-by-itself-in-pr please check the link – bajran Aug 09 '18 at 07:52