forked from OSSPhilippines/covid19-tracker-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
25 lines (20 loc) · 763 Bytes
/
app.js
File metadata and controls
25 lines (20 loc) · 763 Bytes
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
const express = require('express'),
app = express(),
util = require('./bin/util'),
fs = require('fs'),
covid19 = require('./lib/cli');
// set port
const port = process.env.port || 7070;
// package.json info
const pkg = JSON.parse(fs.readFileSync('package.json'));
// global route for covid19 tracker
app.get('/', async (req, res, next) => {
const userAgent = req.headers['user-agent'];
if (util.isCommandline(userAgent)) {
await res.send(covid19.covid19globaltracker());
return null;
}
return next();
});
app.get('*', (req, res) => res.send(`Something went wrong? Contact the developer!\n`));
app.listen(port, () => console.log(`COVID-19 Tracker v${pkg.version} is listening on port ${port}!`));