-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.js
More file actions
31 lines (24 loc) · 699 Bytes
/
app.js
File metadata and controls
31 lines (24 loc) · 699 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
30
31
// app.js - Code to create an express server, incorporting middleware and the main /api route/router
require("./db/connection.js");
const express = require("express");
const cors = require("cors");
const apiRouter = require("./routes/api.router.js");
const {
handleCustomErrors,
handleMdbErrors,
handleServerErrors,
handle404s,
} = require("./errors/errors.js");
// Initalise server
const app = express();
// Initalise middleware (CORS & JSON)
app.use(cors());
app.use(express.json());
// Router Endpoints
app.use("/api", apiRouter);
// Error handling
app.all("*", handle404s);
app.use(handleCustomErrors);
app.use(handleMdbErrors);
app.use(handleServerErrors);
module.exports = app;