forked from bbachi/local-minikube-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (29 loc) · 968 Bytes
/
index.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
37
38
39
const http = require('http');
const qs = require('querystring');
const url = require('url');
const port = process.env.PORT || 3000
const server = http.createServer((req,res) => {
if(req.method !== 'GET') handleError(res, 405)
if(req.url === '/') {
res.writeHead(200, {'Content-Type' : 'text/html'});
res.statusCode = 200;
res.write(`<h1>Hello World</h1>`);
res.end();
}
const {pathname, query} = url.parse(req.url);
if(pathname === '/hello') {
res.writeHead(200, {'Content-Type' : 'text/html'});
res.statusCode = 200;
const {name} = qs.parse(query);
res.write(`<h1>You sent the name: ${name}</h1>`);
res.end();
}
handleError(res, 404);
});
function handleError(res, code) {
res.statusCode = code;
res.end(`{"error": "${http.STATUS_CODES[code]}"}`);
}
server.listen(port, () => {
console.log(`Server listening on the port ${port}`);
})