-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalternate.js
More file actions
24 lines (22 loc) · 850 Bytes
/
alternate.js
File metadata and controls
24 lines (22 loc) · 850 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const http = require('http');
const url = require('url');
var server = http.createServer((request, response) => {
var method = request.method;
var uri = url.parse(request.url);
console.log(method, uri.pathname, 'was requested');
if(method == 'POST' && uri.pathname == '/api/message') {
response.writeHead(200, {'Content-Type': 'application/json'});
response.end(JSON.stringify(helloWorld));
}
else if(method == 'GET' && uri.pathname == '/api/messages') {
response.writeHead(200, {'Content-Type': 'application/json'});
response.end(JSON.stringify(helloWorld));
}
else {
response.writeHead(404, {'Content-Type': 'application/json'});
response.end(JSON.stringify(fourZeroFour));
}
});
var port = 8080;
server.listen(port);
console.log('Server started at port', port);