-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
53 lines (36 loc) · 1.07 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
48
49
50
51
52
53
/** Express app for jobly. */
const express = require("express");
const app = express();
const path = require('path');
const cors = require("cors");
app.use(express.json());
app.use(cors());
// add logging system
const morgan = require("morgan");
app.use(morgan("tiny"));
const usersRoutes = require("./routes/users");
const companiesRoutes = require("./routes/companies");
const jobsRoutes = require("./routes/jobs");
const authRoutes = require("./routes/auth");
app.use("/companies", companiesRoutes);
app.use("/jobs", jobsRoutes);
app.use("/users", usersRoutes);
app.use("/", authRoutes);
app.use(express.static(path.join(__dirname, 'build')));
/** 404 handler */
app.use(function (req, res, next) {
const err = new Error("Not Found");
err.status = 404;
// pass the error to the next piece of middleware
return next(err);
});
/** general error handler */
app.use(function (err, req, res, next) {
if (err.stack) console.log(err.stack);
res.status(err.status || 500);
return res.json({
error: err,
message: err.message
});
});
module.exports = app;