-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
65 lines (54 loc) · 1.55 KB
/
app.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import express from "express";
import axios from "axios";
import path from "path";
const app = express();
const port = 3000;
app.use(express.static("public"));
app.listen(port, () => {
console.log("Frontend container is running and listening at port: " + port);
});
app.get("/api/timezone/", function(req, res) {
const timezone = req.query.tz;
const requestURL = "http://time-microservice:4000/api/timezone/?tz=" + timezone;
var config = {
method: 'get',
url: requestURL,
headers: {}
};
axios(config)
.then(function (response) {
res.status(200).send(response.data);
})
.catch(function (error) {
if (error.response) {
res.status(504).send("Error occurred! Reason: " + error.response.data)
}
else {
res.status(504).send("The time container cannot be reached. Check if it is online!")
}
});
});
app.get("/api/weather/", function(req, res) {
const city = req.query.c;
const requestURL = "http://weather-microservice:4001/api/weather/?c=" + city;
var config = {
method: 'get',
url: requestURL,
headers: {}
};
axios(config)
.then(function (response) {
res.status(200).send(response.data);
})
.catch(function (error) {
if (error.response) {
res.status(504).send("Error occurred! Reason: " + error.response.data)
}
else {
res.status(504).send("The weather container cannot be reached. Check if it is online!")
}
});
});
app.get("*", function(req, res) {
res.status(200).sendFile("public/index.html", { root: path.resolve(path.dirname('')) });
});