-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
50 lines (41 loc) · 1.22 KB
/
Copy pathindex.js
File metadata and controls
50 lines (41 loc) · 1.22 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
46
47
48
49
50
import dotenv from "dotenv";
import cors from "cors";
import { connectToMongo } from "./db.js";
import express from "express";
import cookieParser from "cookie-parser";
dotenv.config();
const app = express();
app.set("trust proxy", 1);
const PORT = process.env.PORT || 5000;
app.use(cookieParser());
app.use(
cors({
origin: [
"https://work-space-pro-frontend.vercel.app",
"http://localhost:3000",
"http://localhost:5173"
],
credentials: true,
methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
allowedHeaders: ["Content-Type", "Authorization"]
})
);
app.use(express.json());
app.get("/", (req, res) => {
res.send("API IS WORKING....");
})
import authRouter from "./src/routes/auth.routes.js"
import NoteRouter from "./src/routes/notes.routes.js"
import taskRouter from "./src/routes/task.routes.js"
import errorMiddleware from "./src/middleware/error.middleware.js";
app.use('/api/notes', NoteRouter);
app.use('/api/auth', authRouter);
app.use('/api/task', taskRouter);
const startServer = async () => {
await connectToMongo();
app.listen(PORT, () => {
console.log(`Workspace Server listening at http://localhost:${PORT}`);
});
};
app.use(errorMiddleware);
startServer();