-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (43 loc) · 1.24 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
import express from "express";
import mongoose from "mongoose";
import cookieParser from "cookie-parser";
import dotenv from "dotenv";
import path from "path";
import connectDB from "./config/db.js";
dotenv.config();
// import { Path } from "mongoose";
// database connect
connectDB();
// user defined module
import userRouter from "./routes/user.js";
import authRouter from "./routes/auth.js";
import eventRouter from "./routes/event.js";
const port = 3000;
const app = express();
// express middleware
app.use(express.json());
app.use(cookieParser());
// user defined route middleware
app.use("/api/user", userRouter);
app.use("/api/auth", authRouter);
app.use("/api/event", eventRouter);
app.use((err, req, res, next) => {
const statusCode = err.statusCode || 500;
const message = err.message || "internal server error";
return res.status(statusCode).json({
success: false,
statusCode,
message,
});
// next();
});
if (process.env.NODE_ENV === "production") {
const __dirname = path.resolve();
app.use(express.static(path.join(__dirname, "/client/dist")));
app.get("*", (req, res) =>
res.sendFile(path.resolve(__dirname, "cleint", "dist", "index.html"))
);
}
app.listen(port, () => {
console.log(`running ${port}`);
});