-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.js
33 lines (21 loc) · 980 Bytes
/
web.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Create a HTTP server on port 8000
// Send plain text headers and 'Hello World' to each client
var http = require('http');
var port = process.env.PORT || 8000;
var counter = 0;
http.createServer(function (req, res) {
// increment the counter for each visitor request
counter=counter+1;
var path = req.url;
console.log("requested=" + path + " counter=" + counter);
res.writeHead(200, {'Content-Type': 'text/html'}); // prepare response headers
if (path == "/") {
res.end("Hello World. You are requestor # " + counter + ".<br><a href='/page2'>Page 2</a>\n" + ".<br><a href='/page3'>Page 3</a>\n");
} else if (path == "/page2") {
res.end("This is page 2. <a href='/'>Back.</a>\n"); // send response and close connection
} else if (path == "/page3") {
res.end("This is page 3. <a href='/'>Back.</a>\n"); // send response and close connection
}
}).listen(port);
// console info message
console.log('Server running at http://127.0.0.1:' + port);