-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (34 loc) · 1.14 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
const express = require("express");
const app = express();
const { PORT } = require("./util/config");
const { connectToDatabase } = require("./util/db");
const {
requestLogger,
unknownEndpoint,
errorHandler,
} = require("./util/middleware");
const blogsRouter = require("./controllers/blogs");
const authorsRouter = require("./controllers/authors");
const usersRouter = require("./controllers/users");
const readingListsRouter = require("./controllers/reading_lists");
const adminRouter = require("./controllers/admin");
const loginRouter = require("./controllers/login");
const logoutRouter = require("./controllers/logout");
app.use(express.json());
app.use(requestLogger);
app.use("/api/blogs", blogsRouter);
app.use("/api/authors", authorsRouter);
app.use("/api/users", usersRouter);
app.use("/api/readinglists", readingListsRouter);
app.use("/api/admin", adminRouter);
app.use("/api/login", loginRouter);
app.use("/api/logout", logoutRouter);
app.use(unknownEndpoint);
app.use(errorHandler);
const start = async () => {
await connectToDatabase();
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
};
start();