Skip to content

Instantly share code, notes, and snippets.

@yushulx
Created July 10, 2020 06:37
Show Gist options
  • Save yushulx/e6cf69afa9e4ab1cfdfdeb00d2d27a2a to your computer and use it in GitHub Desktop.
Save yushulx/e6cf69afa9e4ab1cfdfdeb00d2d27a2a to your computer and use it in GitHub Desktop.
const http = require('http');
var server = http.createServer(function (req, res) {
if (req.url === '/' || req.url === '/index.htm') {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.write(html);
res.end();
}
else if (req.url.startsWith("/image")) {
res.writeHead(200, { 'Content-Type': 'image/jpeg' });
res.write(img);
res.end();
}
else
res.end('Invalid Request!');
});
server.listen(2020);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment