Country and global informations

This commit is contained in:
Daniel Bulant 2020-03-11 12:44:34 +01:00
parent 9cb2443179
commit 2195488eae
2 changed files with 43 additions and 1 deletions

View file

@ -2,12 +2,42 @@ const express = require("express");
const app = express();
const PORT = 1025;
const cases = {};
app.get("/", (req, res)=>{
res.json({
code: 200,
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, ()=>{
console.log("[APP] Ready on port " + PORT);

View file

@ -1 +1,13 @@
# Endpoints
## country
`/country/:country`
Shows information about given country.
## global
`/global`
Shows global informations.