-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
27 lines (20 loc) · 876 Bytes
/
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
const express = require("express");
const methodOverride = require("method-override");
const bodyParser = require("body-parser");
const config = require("./config");
const app = express();
const router = express.Router();
app.use(bodyParser.json()); // parse application/json
app.use(bodyParser.urlencoded({ extended: true })); // parse application/x-www-form-urlencoded
app.use(methodOverride("X-HTTP-Method-Override")); // simulate PUT and DELETE
app.use("/api/v1", router);
require("./routes/unauthenticated")(router);
if (process.env.NODE_ENV === "dev") require("./middlewares")(router);
require("./routes")(router);
app.use((err, req, res, next) => {
if (process.env.NODE_ENV === "dev") {
console.error(err.stack);
res.json({ message: err.message });
} else res.json(Object.keys(err).length ? err : { message: err.message });
});
module.exports = app;