Created
February 18, 2022 13:47
-
-
Save secoats/6ead55a79c3020cc9b3c3ea7c311dfdd to your computer and use it in GitHub Desktop.
nodejs server with Cors Allow Origin Wildcard
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 cors = require('cors'); | |
var app = express(); | |
// sudo apt install nodejs | |
// npm install express cors | |
// nodejs server.js | |
const PORT = 8888; | |
app.use(cors()); // Equivalent to Cors Allow Origin wildcard "*" | |
app.use((req, res, next) => { | |
console.log(`[REQ] ${req.method} - ${req.url}`); | |
next(); | |
}); | |
app.use(express.static('public')); // serve files in ./public/ | |
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