Cors - Http Options Error With Angular And Express
I'm trying to make a POST to my API from an Angularjs client, I have this configuration on the server which is running in another domain: app.use(function(req, res, next) { res.s
Solution 1:
In fact most browsers for security principles does not allow clientside js code to request resource out of same host.
But, it's allowed when resource owner tell to client browser that his sharing resource by adding Cross Origin Resource Sharing headers in response.
To not to guess with headers use cors package - it will do all dirty job for You.
npm install cors --save
and then:
var express = require('express')
, cors = require('cors')
, app = express();
app.use(cors());
that's all :)
additional docs here: https://www.npmjs.com/package/cors
Solution 2:
I see, that this topic is a little bit older, but I found a little typo in your ACCESS-CONTROL-ALLOW-METHODS
.
Just wanted to share this for other users with a similar problem when they copy & paste:
Access-Control-Allow-Methods: GET, POST, PUT, OPTIONS, DETELE
There is a typo in DELETE
.
Post a Comment for "Cors - Http Options Error With Angular And Express"