Skip to content

Instantly share code, notes, and snippets.

@chris-gunawardena
Created June 19, 2018 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chris-gunawardena/1c042dd9324892e7750e93d2363661f0 to your computer and use it in GitHub Desktop.
Save chris-gunawardena/1c042dd9324892e7750e93d2363661f0 to your computer and use it in GitHub Desktop.
CORS server example
var express = require('express')
var app = express()
var port = 8081;
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.header("Access-Control-Allow-Methods", "POST, PUT, GET, OPTIONS");
next();
});
app.get('/status', function(req, res, next) {
// Handle the get for this route
res.json({msg: 'This is CORS-enabled'});
});
app.listen(port, function () {
console.log('CORS-enabled web server listening on port ' + port)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment