2

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
  • 13,082
  • 7
  • 49
  • 71
luk
  • 65
  • 3
  • 14

1 Answers1

3

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,341
  • 13
  • 22
  • 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