-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
72 lines (61 loc) · 1.99 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
65
66
67
68
69
70
71
72
var express = require("express"),
app = express(),
ejs = require("ejs");
const request = require('request'),
bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({extended: true}));
app.set('view engine', "ejs");
app.use(express.static(__dirname + "/public"));
app.get("/", function(req, res){
res.redirect("/home");
});
app.get("/home", function(req, res){
res.render("home");
});
app.get('/news', function(req, res){
var totalData;
var statesData;
var state = "Delhi";
if(req.query.state){
state = req.query.state;
}
// console.log(req.query.state);
request('https://api.covidindiatracker.com/total.json', { json: true }, function (error, response, body) {
if(error){
console.log(error);
}else{
if(response && response.statusCode){
totalData = body;
// accessing new API
request('https://api.covidindiatracker.com/state_data.json', { json: true }, function (error, response, body) {
if(error){
console.log(error);
}else{
if(response && response.statusCode){
statesData = body;
// console.log({totalData, statesData});
res.render("index", {totalData: totalData, statesData: statesData, state: state});
}
}
});
// Done here
}
}
});
});
app.get("/covidCentres", function(req, res){
res.render("covidCentres");
});
app.get("/faq", function(req, res){
res.render("faq");
});
app.get("/symp", function(req, res){
res.render("symp");
});
app.get("/thankYou", function(req, res){
res.render("thankYou");
});
var server = app.listen(process.env.PORT || 3000, function(){
var port = server.address().port;
console.log("The server has started on port " + port);
});