mirror of
https://github.com/danbulant/covid
synced 2026-07-07 12:11:10 +00:00
Country and global informations
This commit is contained in:
parent
9cb2443179
commit
2195488eae
2 changed files with 43 additions and 1 deletions
32
app/index.js
32
app/index.js
|
|
@ -2,12 +2,42 @@ const express = require("express");
|
||||||
const app = express();
|
const app = express();
|
||||||
const PORT = 1025;
|
const PORT = 1025;
|
||||||
|
|
||||||
|
const cases = {};
|
||||||
|
|
||||||
app.get("/", (req, res)=>{
|
app.get("/", (req, res)=>{
|
||||||
res.json({
|
res.json({
|
||||||
code: 200,
|
code: 200,
|
||||||
type: "nothing_to_show"
|
type: "nothing_to_show"
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
|
app.get("/country/:country", (req, res)=>{
|
||||||
|
if(!cases.countries){
|
||||||
|
cases = JSON.parse(require("fs").readFileSync(__dirname + "/../cases.json"));
|
||||||
|
}
|
||||||
|
if(!cases.countries[req.params.country]){
|
||||||
|
return res.status(404).json({
|
||||||
|
code: 404,
|
||||||
|
type: "e_country_not_found"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
res.json({
|
||||||
|
code: 200,
|
||||||
|
type: "country",
|
||||||
|
data: cases.countries[req.params.country]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get("/global", (req, res)=>{
|
||||||
|
if(!cases.global){
|
||||||
|
cases = JSON.parse(require("fs").readFileSync(__dirname + "/../cases.json"));
|
||||||
|
}
|
||||||
|
res.json({
|
||||||
|
code: 200,
|
||||||
|
type: "country_global",
|
||||||
|
data: cases.global
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
app.listen(PORT, ()=>{
|
app.listen(PORT, ()=>{
|
||||||
console.log("[APP] Ready on port " + PORT);
|
console.log("[APP] Ready on port " + PORT);
|
||||||
|
|
|
||||||
|
|
@ -1 +1,13 @@
|
||||||
# Endpoints
|
# Endpoints
|
||||||
|
|
||||||
|
## country
|
||||||
|
|
||||||
|
`/country/:country`
|
||||||
|
|
||||||
|
Shows information about given country.
|
||||||
|
|
||||||
|
## global
|
||||||
|
|
||||||
|
`/global`
|
||||||
|
|
||||||
|
Shows global informations.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue