forked from OSSPhilippines/covid19-tracker-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.ts
More file actions
35 lines (27 loc) · 1.06 KB
/
api.ts
File metadata and controls
35 lines (27 loc) · 1.06 KB
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
import express from "express";
import morgan from "morgan";
import { dashboardRouter } from "./api/dashboardRouter";
import { errorHandler } from "./api/errorHandler";
import { plainRouter } from "./api/plainRouter";
import { regularRouter } from "./api/regularRouter";
import { userAgentMiddleware } from "./api/userAgent";
import { lines } from "./utils/libs/getResponses";
const port = parseInt(process.env.PORT!) || 7070;
const app = express();
app.use(morgan("common"));
app.use("/history/web/charts", dashboardRouter);
app.use(userAgentMiddleware);
app.use("/history/charts", dashboardRouter);
/**
* Plain CMD/Basic routes have both quiet and full modes
* Same with regular / routes with ansi color codes
*/
app.use(["/quiet/basic", "/quiet/cmd", "/quiet/plain"], plainRouter);
app.use(["/basic", "/cmd", "/plain"], plainRouter);
app.use(["/quiet", "/"], regularRouter);
app.use("/", errorHandler);
// Not found handler
app.use("*", (_req, res) => res.status(404).send(lines.notFound));
app.listen(port, () => {
console.log(`Express listening on port ${port}`);
});