-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
50 lines (40 loc) · 1.22 KB
/
server.js
File metadata and controls
50 lines (40 loc) · 1.22 KB
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
40
41
42
43
44
45
46
47
48
49
50
'use strict';
const express = require('express');
let id = 0;
// Constants
const PORT = 8080;
const HOST = '0.0.0.0';
// App
const app = express();
app.get('/hello', (req, res) => {
res.send('Hello world\n');
});
var request = require('request');
app.get('/instructor/:id', (req, res) => {
id = Number(req.params.id)
let name = ""
request(String(`http://backend:8080/instructor/${id}`), function (error, response, body) {
if (!error && response.statusCode == 200) {
var obj = JSON.parse(body);
name = "Hello "+obj.firstName + " " + obj.lastName
res.send(name);
}
})
});
app.get('/student/:id', (req, res) => {
id = Number(req.params.id)
let name = ""
request(String(`http://backend:8080/student/${id}`), function (error, response, body) {
if (!error && response.statusCode == 200) {
var obj = JSON.parse(body);
if (id == 5) {
name = "Hello "+obj.firstName + " " + obj.lastName + ", You need to improve on your skills"
} else {
name = "Hello "+obj.firstName + " " + obj.lastName + ", You are going to become a great DevOps Engineer"
}
res.send(name);
}
})
});
app.listen(PORT, HOST);
console.log(`Running on http://${HOST}:${PORT}`);