Victor Oliveira
Victor Oliveira

Reputation: 1129

Restify and vue cors cross domain blocked

I have a restify server running my API, and I am defining cors middleware as follow:

server.use(restify.acceptParser(server.acceptable));
server.use(restify.queryParser());
server.use(restify.bodyParser({
  multiples: true,
  mapParams: false
}));
server.pre(restify.CORS())
server.use(restify.fullResponse())
server.use(
  function crossOrigin(req,res,next){
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
  return next();
});

but I am always getting this error message:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://myroute... (Reason: CORS preflight channel did not succeed).

What am I doing wrong?

Upvotes: 0

Views: 885

Answers (2)

Victor Oliveira
Victor Oliveira

Reputation: 1129

It happened because restify.CORS() is deprecated at restify new version, at least I see it here:

https://github.com/restify/node-restify/issues/1151

"The restify CORS plugin will be deprecated in the upcoming 5.x release in favor of https://github.com/TabDigital/restify-cors-middleware"

I changed for this plugin and everything worked again.

Upvotes: 1

Jonathan Goodman
Jonathan Goodman

Reputation: 371

Change:

server.pre(restify.CORS())

to:

server.use(restify.CORS())

Upvotes: 0

Related Questions