0

I have one main server which have all files and information and i have build another nodejs project to serve images. When i am trying to connect with it i see XMLHttpRequest cannot load http://localhost:2000/addImageURL.The 'Access-Control-Allow-Origin' header has a value 'http://localhost:8754' that is not equal to the supplied origin. Origin 'http://127.0.0.1:8754' is therefore not allowed access..
To connect i am using angular with $http. On the server i have white listed my 8754 port like below.

app.use(function (req, res, next) {
    res.setHeader('Access-Control-Allow-Origin', 'http://localhost:8754');
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
    res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
    res.setHeader('Access-Control-Allow-Credentials', true);
    next();
});

Update

If i modify all urls to 127.0.0.1 then i get below error: XMLHttpRequest cannot load http://127.0.0.1/addImageURL. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:8754' is therefore not allowed access.

3

1 Answer 1

1

Try this

res.setHeader('Access-Control-Allow-Origin', *);

If it works, it meant the url you have provided for the cross origin 'http://127.0.0.1:8754' is wrong.

Sign up to request clarification or add additional context in comments.

2 Comments

when i am putting * in '*' i am getting error on client side: XMLHttpRequest cannot load http://127.0.0.1/addImageURL. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:8754' is therefore not allowed access.
ok, i found my fail part of code :) Miss to give port inside post from client side.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.