-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
43 lines (34 loc) · 1008 Bytes
/
server.js
File metadata and controls
43 lines (34 loc) · 1008 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
32
33
34
35
36
37
38
39
40
41
42
43
import express from "express";
import cors from "cors";
import dotenv from "dotenv";
import connectDB from "./db/cofig.db.js";
import cookieParser from "cookie-parser";
// Load environment variables
dotenv.config();
// Connect to the database
connectDB();
// Initialize express app
const app = express();
const PORT = process.env.PORT || 5000;
const uri = process.env.CLIENT_URL || "http://localhost:5173";
// Middleware
app.use(cookieParser());
app.use(
cors({
origin: uri,
credentials: true, // Allow cookies
})
);
app.use(express.json());
// Routes
import authRouter from "./routes/auth.routes.js";
import friendRoutes from "./routes/friend.routes.js";
import userRouter from "./routes/user.routes.js";
app.get("/api", (req, res) => {
res.send("Welcome to the TrackCoder API");
});
app.use("/api/auth", authRouter);
app.use("/api/friend", friendRoutes);
app.use("/api/user", userRouter);
// Start the server
app.listen(PORT, () => console.log(`Server is running on port ${PORT}`));