Created
June 19, 2018 09:22
-
-
Save chris-gunawardena/1c042dd9324892e7750e93d2363661f0 to your computer and use it in GitHub Desktop.
CORS server example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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