Skip to content

Instantly share code, notes, and snippets.

@w7089
Created January 10, 2019 12:25
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 w7089/88ad987acb91d0c09beb4513b524d9e2 to your computer and use it in GitHub Desktop.
Save w7089/88ad987acb91d0c09beb4513b524d9e2 to your computer and use it in GitHub Desktop.
httpServer.js
server = require('http').createServer()
const fs = require('fs');
server.on('request', (req, res) => {
switch (req.url) {
case '/home':
case '/about':
res.writeHead(200, {'content-type' : 'text/plain'})
res.end(fs.readFileSync(`.${req.url}.html`));
case '/':
res.writeHead(301, {'Location' : '/home'})
res.end()
break
default:
}
// res.write('Hello world\n')
// // req: req.IncomingMessage
// // res: http.ServerResponse
// setTimeout(function() {
// res.write('another hello\n')
// }, 2000)
// setTimeout(function() {
// res.write('2 another hello\n')
// }, 2000)
})
server.listen(8000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment