-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
67 lines (56 loc) · 1.75 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
var PORT = process.env.PORT || 3000;
var express = require("express");
var app = express();
var axios = require("axios");
var bodyParser = require("body-parser");
app.use(express.static("public"));
app.use(bodyParser.urlencoded({extended:true}));
app.get("/",function(req,res){
res.redirect("/global");
});
app.get("/global",function(req,res){
axios("https://api.covid19api.com/summary")
.then(function(response){
res.render("home.ejs",{data : response.data});
})
.catch(function(err){
if(err){
res.render(err);
}
});
});
app.get("/global/:country",function(req,res){
var country = req.query.country.charAt(0).toUpperCase() + req.query.country.slice(1).toLowerCase();
axios("https://api.covid19api.com/summary")
.then(function(response){
res.render("countries.ejs",{data : response.data , country : country});
})
.catch(function(err){
if(err){
res.render(err);
}
});
});
app.get("/india",function(req,res){
axios("https://api.covid19india.org/data.json")
.then(function(response){
res.render("india.ejs",{data : response.data});
})
.catch(function(err){
if(err){
res.render(err);
}
});
});
app.get("/india/:state",function(req,res){
var state = req.query.state.charAt(0).toUpperCase() + req.query.state.slice(1).toLowerCase();
axios("https://api.covid19india.org/data.json")
.then(function(response){
res.render("state.ejs",{data : response.data,state : state});
})
});
// app.get("/India/:state",function(req,res){
// });
app.listen(PORT,function(){
console.log("Hello!! server is working!!");
});