-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.ts
56 lines (45 loc) · 1.31 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
51
52
53
54
55
56
import {Application} from "express";
import config = require("./config/appConfig");
import express = require("express");
import slowDown = require("express-slow-down");
import path = require("path");
const cookieParser: any = require("cookie-parser");
const lessMiddleware: any = require("less-middleware");
import logger = require("morgan");
const isProduction = process.env.NODE_ENV === "production";
const indexRouter: Application = require("./routes");
const app = express();
const speedLimiter = slowDown(config.speedLimit);
app.enable("trust proxy");
app.use(speedLimiter);
app.use(logger("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(lessMiddleware(path.join(__dirname, "public")));
app.use(express.static(path.join(__dirname, "public")));
app.use("/", indexRouter);
/// Error handlers & middle-wares
if (!isProduction) {
// noinspection JSUnusedLocalSymbols
app.use((err, req, res, next) => {
res.status(err.status || 500);
res.json({
errors: {
error: err,
message: err.message,
},
});
});
}
// noinspection JSUnusedLocalSymbols
app.use((err, req, res, next) => {
res.status(err.status || 500);
res.json({
errors: {
error: {},
message: err.message,
},
});
});
module.exports = app;