-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
47 lines (47 loc) · 1.41 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
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const config = require("./config/appConfig");
const express = require("express");
const slowDown = require("express-slow-down");
const path = require("path");
const cookieParser = require("cookie-parser");
const lessMiddleware = require("less-middleware");
const logger = require("morgan");
const isProduction = process.env.NODE_ENV === "production";
const indexRouter = 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;
//# sourceMappingURL=app.js.map