Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';

const http = require('http');
const fs = require('fs');

let port = 3000;
let host = 'localhost';

let newReq = function(obj) {
this.url = obj.url;
this.method = obj.method;
this.httpVersion = obj.httpVersion;
this.headers = obj.headers;
};

let newRes = function(obj) {
this.statusMessage = obj.statusMessage;
this.statusCode = obj.statusCode;
this._header = obj._header;
};

let server = http.createServer((req, res) => {
fs.readFile('./public/index.html', 'utf8', (err, data) => {
res.writeHead(200, {
'Content-Type': 'text/html'
});
let req2 = new newReq(req);
let res2 = new newRes(res);
console.log('loaded');
data = data.replace('{{ req }}', JSON.stringify(req2, null, 2));
data = data.replace('{{ res }}', JSON.stringify(res2, null, 2));
res.end(data);
});
});

server.listen(port, host, () => {
console.log(`Listening at http://${host}:${port}`);
});
Empty file added public/form_data.txt
Empty file.
37 changes: 37 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html>
<head>

</head>
<body>
<h1>All is well</h1>

<h2>Request:</h2>
<pre>{{ req }}</pre>

<h2>Response:</h2>
<pre>{{ res }}</pre>


<form action='/form_data.txt' method="get">
<fieldset>

<legend>Login</legend>

<label for="username">Username</label>
<input type="text" name="username" placeholder="Username">

<label for="password">Password</label>
<input type="password" name="password" placeholder="Password">

<label for="verify_password">Verify Password</label>
<input type="password" name="verify_password" placeholder="Password">

<input type="submit">
</fieldset>
</form>



</body>
</html>