-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello.js
38 lines (28 loc) · 913 Bytes
/
hello.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
"use strict";
let http = require('http');
//const port = 3000;
var port = process.env.PORT||3000;
var host = process.env.HOST||"0.0.0.0";
let server = http.createServer(requestHandler);
function requestHandler(request, response) {
const userAgent = request.headers['user-agent'];
console.log(userAgent);
if(request.url === '/hello' && request.method === 'GET') {
return response.end('world');
}
if(request.url === '/hello' && request.method === 'POST') {
return response.end('world created');
}
if(request.url === '/hello' && request.method === 'PUT') {
return response.end('world updated');
}
if(request.url === '/hello' && request.method === 'DELETE') {
return response.end('world deleted');
}
}
server.listen(port, function(err){
if (err) {
return console.error('Something bad happened', err);
}
console.log(`server is listening on ${host}:${port}`);
});