forked from redhat-appstudio-qe/simple-nodejs-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
25 lines (20 loc) · 619 Bytes
/
Copy pathmain.js
File metadata and controls
25 lines (20 loc) · 619 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
25
const http = require('http');
const Users = require('./users');
const port = process.env.PORT || 8081
function handleGetReq(req, res) {
if (req.url !== '/users') {
return handleError(res, 404)
}
res.setHeader('Content-Type', 'application/json;charset=utf-8');
return res.end(JSON.stringify(Users.getUsers()))
}
function handleError (res, code) {
res.statusCode = code
res.end(`{"error": "${http.STATUS_CODES[code]}"}`)
}
const server = http.createServer((req, res) => {
if (req.method === 'GET') {
return handleGetReq(req, res)
}
});
server.listen(port, () => {+