-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
50 lines (43 loc) · 1.71 KB
/
app.ts
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
import bodyParser from "body-parser";
import { NextFunction, NextHandleFunction } from "connect";
import express, { Application, Handler, Request, Response } from "express";
import cors from "cors";
import config from "./config/config";
import { CorsOriginCallbackFunction, CorsOriginParam } from "./types/corsOptions.type";
import morgan from "morgan";
import createHttpError from "http-errors";
import certificatesRouter from "./routes/certificates.route";
import activitiesRouter from "./routes/activities.route";
import projectsRouter from "./routes/projects.route";
import stacksRouter from "./routes/stacks.route";
import selfInformationsRouter from "./routes/selfInformations.route";
const app: Application = express();
const urlEncoded: NextHandleFunction = bodyParser.urlencoded({
limit: "50mb",
extended: false,
});
const jsonEncoded: NextHandleFunction = express.json({
limit: "50mb",
});
const corsOrigins: NextHandleFunction = cors({
origin: function (origin: CorsOriginParam, callback: CorsOriginCallbackFunction) {
if (!origin) return callback(null, true);
if (config.allowedOrigins.indexOf(origin as never) === -1) {
const msg = 'The CORS policy for this site does not ' + 'allow access from the specified Origin.';
return callback(new Error(msg), false);
}
return callback(null, true);
},
credentials: true,
});
const morganLog: NextHandleFunction = morgan("dev");
app.use(corsOrigins);
app.use(urlEncoded);
app.use(jsonEncoded);
app.use(morganLog);
app.use("/api", certificatesRouter);
app.use("/api", activitiesRouter);
app.use("/api", projectsRouter);
app.use("/api", stacksRouter);
app.use("/api", selfInformationsRouter);
export default app;