mirror of
https://github.com/danbulant/covid
synced 2026-06-19 06:31:12 +00:00
Fix typo & add error handling
This commit is contained in:
parent
a40f0d1726
commit
ef10c5f0b4
1 changed files with 11 additions and 2 deletions
13
app/index.js
13
app/index.js
|
|
@ -13,7 +13,7 @@ app.get("/", (req, res)=>{
|
|||
|
||||
app.get("/country/:country", (req, res)=>{
|
||||
if(!cases.countries){
|
||||
cases = JSON.parse(require("fs").readFileSync(__dirname + "/../cases.json"));
|
||||
cases = JSON.parse(require("fs").readFileSync(__dirname + "/../data/cases.json"));
|
||||
}
|
||||
if(!cases.countries[req.params.country]){
|
||||
return res.status(404).json({
|
||||
|
|
@ -30,7 +30,7 @@ app.get("/country/:country", (req, res)=>{
|
|||
|
||||
app.get("/global", (req, res)=>{
|
||||
if(!cases.global){
|
||||
cases = JSON.parse(require("fs").readFileSync(__dirname + "/../cases.json"));
|
||||
cases = JSON.parse(require("fs").readFileSync(__dirname + "/../data/cases.json"));
|
||||
}
|
||||
res.json({
|
||||
code: 200,
|
||||
|
|
@ -39,6 +39,15 @@ app.get("/global", (req, res)=>{
|
|||
});
|
||||
});
|
||||
|
||||
|
||||
app.use(function (err, req, res, next) {
|
||||
console.error(err);
|
||||
res.status(500).json({
|
||||
code: 500,
|
||||
type: "e_internal"
|
||||
});
|
||||
})
|
||||
|
||||
app.listen(PORT, ()=>{
|
||||
console.log("[APP] Ready on port " + PORT);
|
||||
})
|
||||
Loading…
Reference in a new issue