You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
703 B
29 lines
703 B
3 years ago
|
const http = require('http')
|
||
|
const url = require('url');
|
||
|
|
||
|
function json_response(code, object, reponse) {
|
||
|
reponse.statusCode = 200;
|
||
|
res.setHeader('content-type', 'Application/json');
|
||
|
JSON.stringify(object);
|
||
|
res.end();
|
||
|
}
|
||
|
|
||
|
const server = http.createServer(function (request, response) {
|
||
|
parsedUrl = url.parse(request.url, true);
|
||
|
if(request.url === "/") {
|
||
|
json_response(200,{status : "active"},response);
|
||
|
}
|
||
|
else if(request.url.startsWith("/info")) {
|
||
|
console.log(parsedUrl);
|
||
|
console.log(request.method);
|
||
|
response.statusCode = 200;
|
||
|
response.end('done');
|
||
|
}
|
||
|
else {
|
||
|
response.statusCode = 404;
|
||
|
response.end('nothing');
|
||
|
}
|
||
|
});
|
||
|
|
||
|
server.listen(8082);
|