-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
45 lines (36 loc) · 1.15 KB
/
index.js
File metadata and controls
45 lines (36 loc) · 1.15 KB
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
import "dotenv/config";
import express from "express";
import cookieParser from "cookie-parser";
import path from "path";
const app = express();
const port = process.env.PORT || 3001;
//middlewares
app.use(express.json());
app.use(cookieParser());
import authRouter from "./server/src/routes/auth.route.js";
import userRouter from "./server/src/routes/user.route.js";
import postRouter from "./server/src/routes/post.route.js";
import commentRouter from "./server/src/routes/comment.route.js";
app.use("/api/auth", authRouter);
app.use("/api/user", userRouter);
app.use("/api/post", postRouter);
app.use("/api/comment", commentRouter);
const __dirname = path.resolve();
app.use(express.static(path.join(__dirname, "client/dist")));
app.use("*", (req, res) => {
res.sendFile(path.join(__dirname, "client", "dist", "index.html"));
});
//not found
import notFound from "./server/src/utils/notFound.js";
app.use(notFound);
//database
import connectDB from "./server/src/db/index.js";
connectDB()
.then(() => {
app.listen(port, () => {
console.log(`app listening on port ${port}`);
});
})
.catch(() => {
console.log("Connection failed!");
});