forked from danawoodman/docker-node-hello-world
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
36 lines (30 loc) · 1.09 KB
/
server.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
34
35
36
var http = require('http');
var url = require('url');
var port = 4000;
var server = http.createServer(function (request, response) {
// Extract the URL path from the request
var path = request.url;
var query = url.parse(path,true).query;
console.log("query", query);
// Handle different routes
if (path === '/') {
console.log("Success, nothing to see here");
response.writeHead(200, { 'Content-Type': 'text/plain' });
response.end('Hello World\n');
} else if (path === '/about') {
console.log("About to go down");
response.writeHead(200, { 'Content-Type': 'text/plain' });
response.end('About page\n');
} else if (path === '/error') {
console.log("500 500 Big Error Occured");
response.writeHead(200, { 'Content-Type': 'text/plain' });
response.end('Contact page\n');
} else {
// Handle unknown routes with a 404 response
console.log("This is a 404 message");
response.writeHead(404, { 'Content-Type': 'text/plain' });
response.end('Not Found\n');
}
});
server.listen(port);
console.log('Server running at http://localhost:' + port);