forked from gchq/CyberChef-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
52 lines (38 loc) · 1.1 KB
/
app.js
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
50
51
52
import fs from "fs";
import YAML from "yaml";
import express from "express";
import cookieParser from "cookie-parser";
import pino from "express-pino-logger";
import swaggerUi from "swagger-ui-express";
import errorHandler from "./lib/errorHandler.js";
// https://helmetjs.github.io/
import helmet from "helmet";
import bakeRouter from "./routes/bake";
import magicRouter from "./routes/magic";
const app = express();
app.disable("x-powered-by");
if (process.env.NODE_ENV === "production") {
app.use(pino({
level: "warn"
}));
app.use(helmet());
} else {
app.use(pino({
level: "debug",
prettyPrint: true
}));
}
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
// Swagger docs
const swaggerFile = fs.readFileSync("./swagger.yml", "utf8");
// Routes
app.use("/bake", bakeRouter);
app.use("/magic", magicRouter);
// Default route
app.use("/", swaggerUi.serve);
app.get("/", swaggerUi.setup(YAML.parse(swaggerFile)));
// Error handling - place after all other middleware and routes
app.use(errorHandler);
export default app;