Skip to content

Instantly share code, notes, and snippets.

@secoats
Created February 18, 2022 13:47
Show Gist options
  • Save secoats/6ead55a79c3020cc9b3c3ea7c311dfdd to your computer and use it in GitHub Desktop.
Save secoats/6ead55a79c3020cc9b3c3ea7c311dfdd to your computer and use it in GitHub Desktop.
nodejs server with Cors Allow Origin Wildcard
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