From f8e01ec15d432f9f4120b4ba85d3fe384dc9d987 Mon Sep 17 00:00:00 2001 From: JFarenci <31667933+JFarenci@users.noreply.github.com> Date: Tue, 6 Mar 2018 14:58:53 -0600 Subject: [PATCH 1/2] Add files via upload --- app.js | 24 ++++++++++++++++++++++++ public/index.html | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 app.js create mode 100644 public/index.html diff --git a/app.js b/app.js new file mode 100644 index 0000000..7f96a9c --- /dev/null +++ b/app.js @@ -0,0 +1,24 @@ +var http = require('http'), host = 'localhost', port = 3000; +var fs = require('fs'); + +var server = http.createServer(function(req, res) { + fs.readFile('./public/index.html', 'utf8', function(err, data) { + if (err) { + res.writeHead(404); + res.end('404 Not Found'); + } else { + res.writeHead(200, {'Content-Type': 'text/html'}); + let ReqProp = ['url', 'method', 'httpVersion', 'headers']; + let ResProp = ['statusMessage', 'statusCode', '_header']; + let request = ReqProp.map((prop) => {return { [prop] : req[prop] }; }); + let response = ResProp.map((prop) => {return { [prop] : res[prop] }; }); + let display = data.replace('{{ req }}', JSON.stringify(request)) + .replace('{{ res }}', JSON.stringify(response)); + res.end(display); + } + }); +}); + +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..ee5d8eb --- /dev/null +++ b/public/index.html @@ -0,0 +1,40 @@ + +
+{{ req }}
+
+ {{ res }}
+
+
+
+
+
+
+
+
+
+
+
From 95858e027d9309db08a1bd65c5ef3dc8d79539e9 Mon Sep 17 00:00:00 2001
From: JFarenci <31667933+JFarenci@users.noreply.github.com>
Date: Tue, 6 Mar 2018 14:59:16 -0600
Subject: [PATCH 2/2] Update README.md
---
README.md | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 29b1d71..03dabf5 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,3 @@
# assignment_build_a_nodejs_server
-Building your first Node.js server and exploring the request and response objects
+
+Jacob Farenci