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
31 changes: 31 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const http = require('http');
const fs = require('fs');

const hostname = 'localhost';
const port = 3000;

const server = http.createServer(function(req, res){
fs.readFile('./public/index.html', 'utf8', function(err, data){
if(err){
res.writeHead(404);
res.end("404 Page Not Found");
}else{
resVar = JSON.stringify({statusMessage: res.statusMessage,
statusCode: res.statusCode,
header: res._header}, null, 2);
reqVar = JSON.stringify({url: req.url,
method: req.method,
httpVersion: req.httpVersion,
headers: req.headers}, null, 2);
let data2 = data.replace(/{{ res }}/, resVar);
let data3 = data2.replace(/{{ req }}/, reqVar);
res.writeHead(200, {
'Content-Type': 'text/html'
});
res.end(data3);
}
});
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
29 changes: 29 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8">
<title></title>
<meta name="description" content="">
<meta name="author" content="Gene Tinderholm">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="">
</head>
<body>
<h1>It worked!</h1>
<br>
<h2>Request:</h2>
<pre>{{ req }}</pre>
<br>
<h2>Response:</h2>
<pre>{{ res }}</pre>
<br>
<form action="/" method="get">
<label for="name">Username:</label>
<input type="text" name="name">
<label for="password">Password:</label>
<input type="password" name="password">
<input type="submit" value="Submit">
</form>
</body>
</html>
Loading