Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

how to temporally disable the cors ? #1609

Closed
helxsz opened this issue Nov 4, 2016 · 7 comments
Closed

how to temporally disable the cors ? #1609

helxsz opened this issue Nov 4, 2016 · 7 comments
Assignees
Milestone

Comments

@helxsz
Copy link

helxsz commented Nov 4, 2016

currently I am using the angular- cli to build a web app, which uses the meanjs api, so they are using the local ip address but the two servers are based on two different ports. Because of this, the angular web app receives Origin 'http://localhost:4200' is therefore not allowed access.

how would I be able to shortly disable the cors so I can easily test the angular app?

best rgds

@mleanos
Copy link
Member

mleanos commented Nov 4, 2016

You can enable CORS on your destination API. I use this in a couple of my projects: https://github.com/expressjs/cors. Their documentation is really good, and the library's api is easy to use.

You will have to add a cors configuration for your express route(s) with a origin of http://localhost:4200

@mleanos mleanos self-assigned this Nov 4, 2016
@mleanos mleanos added this to the q milestone Nov 4, 2016
@helxsz
Copy link
Author

helxsz commented Nov 5, 2016

  var corsOptions = {
    origin: 'http://localhost:4200',
    optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204
  };
  app.use(cors());

which works!!

@PManager1
Copy link

@helxsz where in meanjs app should I add this configuration for cors ?

@codydaig
Copy link
Member

@helxsz
Copy link
Author

helxsz commented Nov 24, 2016

@jpca999 as codydaig shows above, in the module.exports.initMiddleware = function (app)

@PManager1
Copy link

Resolved thx guys! :-)

@mg1075
Copy link

mg1075 commented Feb 2, 2017

@helxsz - I think you need to pass corsOptions to the cors() call, otherwise your option setup is ignored. https://github.com/expressjs/cors#simple-usage-enable-all-cors-requests
cors(corsOptions)

@codydaig - I added the cors package, and added configuration for cors in express, but nothing is changing.

I can make the the cross origin request call with angular/js/html in a simple, stand-alone page/app, but with node/express, it's not working; I'm getting the error message.

XMLHttpRequest cannot load <<external url>>. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants