-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
52 lines (42 loc) · 1.27 KB
/
index.js
File metadata and controls
52 lines (42 loc) · 1.27 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
51
52
import express from 'express'
import 'dotenv/config'
import cookieParser from 'cookie-parser';
import bodyParser from 'body-parser';
import connectDB from './config/mongoDB.js';
import authRouter from './routes/authRoutes.js';
import taskRouter from './routes/taskRoutes.js';
import cors from 'cors'
import formRouter from './routes/formRoutes.js';
import responseRouter from './routes/responseRoutes.js';
import adminRouter from './routes/adminRoutes.js';
const PORT = process.env.PORT || 8000
const app = express()
connectDB()
// Middlewares
const ORIGIN = process.env.ORIGIN || 'http://localhost:5173'
console.log("CORS Origin set to:", ORIGIN)
app.use(express.json());
app.use(cookieParser())
app.use(bodyParser.urlencoded({ extended: true }));
app.use(
cors({
origin: [ORIGIN, 'http://localhost:5173'],
credentials: true,
})
);
if (!process.env.MONGO_URI) {
console.error('ERROR: MONGO_URI environment variable is missing.');
process.exit(1);
}
app.get("/", (req, res) => {
res.send("SYNC AIT BACKEND API")
})
// Routes
app.use("/api/auth", authRouter)
app.use("/api/task", taskRouter)
app.use('/api/forms', formRouter)
app.use('/api/response', responseRouter)
app.use('/api/admin', adminRouter);
app.listen(PORT, () => {
console.log("Server Started: ", PORT)
})