diff --git a/app.js b/app.js new file mode 100644 index 0000000..ecdde9f --- /dev/null +++ b/app.js @@ -0,0 +1,41 @@ +var http = require('http'); +var fs = require('fs'); + +var port = 3000; +var host = 'localhost'; + +var server = http.createServer(function(req, res) { + fs.readFile('./public/index.html', 'utf8', function(err, data) { + if (err) { + res.writeHead(404); + res.end('There was an error'); + } else { + res.writeHead(200, { + "Content-Type": 'text/html' + }); + + var smallReq = { + url: req.url, + method: req.method, + httpVersion: req.httpVersion, + headers: req.headers + }; + + var smallRes = { + statusMessage: res.statusMessage, + statusCode: res.statusCode, + _header: res._header + }; + + var replaced = data.replace('{{ req }}', JSON.stringify(smallReq, null, 2)) + .replace('{{ res }}', JSON.stringify(smallRes, null, 2)); + + res.end(replaced); + } + }); +}); + +server.listen(port, host, function() { + console.log(`Listening at http://${ host }:${ port }`); +}); + diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..f5391c7 --- /dev/null +++ b/public/index.html @@ -0,0 +1,20 @@ + + + +
+ + +{{ req }}
+
+ {{ res }}
+
+