From 83db432742b1d9a5bad9c836704c1351d43f6ca6 Mon Sep 17 00:00:00 2001 From: SamuelLangenfeld Date: Wed, 8 Nov 2017 23:36:01 -0500 Subject: [PATCH 1/3] initial server created --- app.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 app.js diff --git a/app.js b/app.js new file mode 100644 index 0000000..412380d --- /dev/null +++ b/app.js @@ -0,0 +1,16 @@ +var http= require('http'); +var fs=require('fs'); + +var port=3000; +var host='localhost'; + + +const server = http.createServer((req, res) => { + res.statusCode = 200; + res.setHeader('Content-Type', 'text/plain'); + res.end('Hello World\n'); +}); + +server.listen(port, host, function(){ + console.log(`Server is Running and Listening at http://${ host }:${ port }`); +}); \ No newline at end of file From bc3a489e86a647e8a88fc3404dd0e2b98e38423b Mon Sep 17 00:00:00 2001 From: SamuelLangenfeld Date: Wed, 8 Nov 2017 23:42:29 -0500 Subject: [PATCH 2/3] reads and outputs html from public folder --- app.js | 17 +++++++++++++---- public/index.html | 8 ++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 public/index.html diff --git a/app.js b/app.js index 412380d..f5ccb90 100644 --- a/app.js +++ b/app.js @@ -5,10 +5,19 @@ var port=3000; var host='localhost'; -const server = http.createServer((req, res) => { - res.statusCode = 200; - res.setHeader('Content-Type', 'text/plain'); - res.end('Hello World\n'); +var server = http.createServer((req, res) => { + fs.readFile('./public/index.html',function(err, data){ + if (err){ + res.writeHead(404); + res.end("File not Found"); + } + else{ + res.writeHead(200,{ + "Content-Type": "text/html" + }); + res.end(data); + } + }); }); server.listen(port, host, function(){ diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..c4d3506 --- /dev/null +++ b/public/index.html @@ -0,0 +1,8 @@ + + + + + +

There is no cow level

+ + \ No newline at end of file From 2d1a44304b8c2c407b9e29b7c5ded331cb01c12f Mon Sep 17 00:00:00 2001 From: SamuelLangenfeld Date: Thu, 9 Nov 2017 22:06:55 -0500 Subject: [PATCH 3/3] add form for submitting data --- app.js | 19 ++++++++++++++++++- public/index.html | 10 ++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app.js b/app.js index f5ccb90..e5d664e 100644 --- a/app.js +++ b/app.js @@ -6,16 +6,33 @@ var host='localhost'; var server = http.createServer((req, res) => { - fs.readFile('./public/index.html',function(err, data){ + fs.readFile('./public/index.html', 'utf-8', function(err, data){ if (err){ res.writeHead(404); res.end("File not Found"); } else{ + var reqObj={ + url:req.url, + method:req.method, + version:req.httpVersion, + header:req.headers + }; + var reqString=JSON.stringify(reqObj, null, 2); res.writeHead(200,{ "Content-Type": "text/html" }); + data=data.replace("{{ req }}", reqString); + var resObj = { + statusMessage:res.statusMessage, + statusCode:res.statusCode, + _header:res._header + }; + var resString=JSON.stringify(resObj, null, 2); + data=data.replace("{{ res }}", resString); res.end(data); + + } }); }); diff --git a/public/index.html b/public/index.html index c4d3506..f3c7381 100644 --- a/public/index.html +++ b/public/index.html @@ -4,5 +4,15 @@

There is no cow level

+

Request:

+
{{ req }}
+ +

Response:

+
{{ res }}
+
+ Username: + Password: + +
\ No newline at end of file