S
S
Sergey Nikolaev2015-06-11 11:04:29
Node.js
Sergey Nikolaev, 2015-06-11 11:04:29

How to disable CORS protection in nodeJS?

Good afternoon, in PHP, to disable CORS protection, I prescribe 3 headers:

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: *');
header('Access-Control-Allow-Headers: content-type');

I tried the same in NodeJS but didn't work. How to disable CORS protection in nodeJS?
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "*");
response.setHeader("Access-Control-Allow-Headers", "content-type");

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Timur Shemsedinov, 2015-06-11
@Devastor

You already wrote almost everything yourself, only you didn’t add origin to Access-Control-Allow-Headers . Need:

res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Headers', 'origin, content-type, accept');

But this may not be the problem, if you try to do it locally and access localhost, then it will not work, these headers will be ignored by the browser. Use local IP instead of localhost write 127.0.0.1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question