-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (43 loc) · 1.27 KB
/
index.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
const express = require("express");
const compression = require("compression");
const helmet = require("helmet");
const bodyParser = require("body-parser");
const cors = require('cors');
require('dotenv').config();
const port = process.env.PORT || 3001;
const app = express();
app.use(compression());
app.use(helmet());
app.use(cors());
// import routers
const jobBoardRouter = require("./routes/jobPost");
const skillsRouter = require("./routes/skill");
const jobTypeRouter = require("./routes/jobType");
const locationRouter = require("./routes/location");
const skillSetRouter = require("./routes/skillSet");
app.use(bodyParser.json());
app.use(
bodyParser.urlencoded({
extended: true,
})
);
app.get("/", (req, res) => {
// api is ready
res.json({ message: "ready!" });
});
// use routers
app.use("/jobPosts", jobBoardRouter);
app.use("/skills", skillsRouter);
app.use("/jobTypes", jobTypeRouter);
app.use("/locations", locationRouter);
app.use("/skillSets", skillSetRouter);
// error handler
app.use((err, req, res, next) => {
const statusCode = err.statusCode || 500;
console.error(err.message, err.stack);
res.status(statusCode).json({ message: err.message });
return;
});
app.listen(port, () => {
console.log(`App listening at http://localhost:${port}`);
});