forked from gordonball/pixly-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
29 lines (22 loc) · 670 Bytes
/
app.js
File metadata and controls
29 lines (22 loc) · 670 Bytes
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
"use strict";
const express = require("express");
const cors = require("cors");
const app = express();
const routes = require("./routes/routes");
app.use(cors());
app.use(express.json());
app.use("/", routes);
/** Handle 404 errors -- this matches everything */
app.use(function (req, res, next) {
throw new NotFoundError();
});
/** Generic error handler; anything unhandled goes here. */
app.use(function (err, req, res, next) {
if (process.env.NODE_ENV !== "test") console.error(err.stack);
const status = err.status || 500;
const message = err.message;
return res.status(status).json({
error: { message, status },
});
});
module.exports = app;