-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.ts
More file actions
49 lines (45 loc) · 1.3 KB
/
app.ts
File metadata and controls
49 lines (45 loc) · 1.3 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import express, { NextFunction, Request, Response } from "express";
import bodyparser from "body-parser";
import morgan from "morgan";
import autogenerateValue from "./autogenerate_value/router";
import APIError from "./utils/api-error";
import embed from "./embed/router";
import qc from "./qc/router";
import order from "./order/router";
import user from "./users/router";
import { authorizeUser } from "./utils/authentication";
import cors from "cors";
import motor from "./motor/router";
import controller from "./controller/router";
import pdi from "./pdi/router";
let app = express();
app.use(morgan("common"));
app.use(cors());
app.use(bodyparser.json());
app.use(bodyparser.urlencoded({ extended: true }));
app.use("/user", user);
app.use(authorizeUser);
app.use("/autogenerateValue", autogenerateValue);
app.use("/qc", qc);
app.use("/embed", embed);
app.use("/pdi", pdi);
app.use("/order", order);
app.use("/motor", motor);
app.use("/controller", controller);
app.use(errorHandler);
function errorHandler(
err: Error,
req: Request,
res: Response,
next: NextFunction
) {
if (err instanceof APIError) {
res.status(err.statusCode).send({
message: err.message,
code: err.code,
});
} else {
res.status(400).send({ message: err.message, code: "ERROR_CODE" });
}
}
export default app;