Last active
February 2, 2023 02:21
-
-
Save xhsdnn/0db61f02c078aecd445337a34f1cb84e to your computer and use it in GitHub Desktop.
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
const http = require('http'); | |
let server; | |
function onRequest(req, res) { | |
console.log('[' + this.name + ']', req.method, req.url); | |
res.setHeader('Access-Control-Allow-Origin', '*'); | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.end('Hello World\n'); | |
} | |
function onListening() { | |
console.log('[' + this.name + '] Listening at http://' + this.address().address + ':' + this.address().port + '/'); | |
} | |
server = http.createServer(); | |
server.name = 'TestServer'; | |
server.on('request', onRequest); | |
server.on('listening', onListening); | |
server.listen(8084, '127.0.0.1'); // ipv4: http://127.0.0.1:8084/ | |
// server.listen(8084, '::'); // ipv6: http://[::]:8084/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment