node.js - Access-Control-Allow-Origin issues even on setting it up -




my nodejs/express includes:

app.use(function handleapperror(err, req, res, next) {     const msg = 'error: app error: ' + util.inspect(err);      // website wish allow connect     res.setheader('access-control-allow-origin', '*');      console.log(msg);     if (res.headerssent) {         next(err);     } else {         res.status(500).send(msg);     } }); 

…but on making call, still end error in chrome:

xmlhttprequest cannot load http://:8080/management-api/v1/bots. response preflight request doesn't pass access control check: no 'access-control-allow-origin' header present on requested resource. origin 'http://localhost:8100' therefore not allowed access.

you need handle options method. try this

app.all("/*", function(req, res, next) {     res.header("access-control-allow-origin", "*");     res.header("access-control-allow-headers", "cache-control, pragma, origin, authorization, content-type, x-requested-with");     res.header("access-control-allow-methods", "get, put, post, delete");     if (req.method === "options")         res.send(200);     else         next(); }); 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -

python - Read npy file directly from S3 StreamingBody -