Skip to content Skip to sidebar Skip to footer

Cors - Access-control-allow-origin Issue

I have an AngularJS web application with a RESTful Jersey Api as Backend. I'm making a call to this API function Create(user) { return $http.post('http://localhost:8080/Nob

Solution 1:

I solved the issue using this solution:

http://www.coderanch.com/t/640189/Web-Services/java/Access-Control-Origin-header-present

But I have another error.

enter image description here

I will do another question cause I think it's a different argument.

Solution 2:

Use CORS NPM and add as a middleware.

var express = require('express')
var cors = require('cors')
var app = express()

app.use(cors())

app.get('/products/:id', function (req, res, next) {
  res.json({msg: 'This is CORS-enabled for all origins!'})
})

app.listen(80, function () {
  console.log('CORS-enabled web server listening on port 80')
})

------------------------- Add this lines in your app.js -------------------------

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');

Post a Comment for "Cors - Access-control-allow-origin Issue"