Skip to content

Instantly share code, notes, and snippets.

@haseebpvt
Created November 18, 2019 14:46
Show Gist options
  • Select an option

  • Save haseebpvt/02b94ad01ea9606f9d61070170a67198 to your computer and use it in GitHub Desktop.

Select an option

Save haseebpvt/02b94ad01ea9606f9d61070170a67198 to your computer and use it in GitHub Desktop.
Code for cors error
//var express = require('express');
//var app = express();
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', "Origin, X-Requested-With, Content-Type, Accept, Authorization");
if (req.method === 'OPTIONS') {
res.header('Access-Control-Allow-Method', 'PUT, POST, PATCH, DELETE, GET');
return res.status(200).json({});
}
next();
});
//app.get('/old', function(req, res) {
//console.log('Get called: ' + value.msg);
//res.send(value);
//});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment