-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (33 loc) · 1.05 KB
/
index.js
File metadata and controls
40 lines (33 loc) · 1.05 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
import express from "express";
import cors from "cors";
import { configDotenv } from "dotenv";
import mongoose from "mongoose";
import cookieParser from "cookie-parser";
import authRouter from "./routers/auth.router.js";
import bookmarkRouter from "./routers/bookmark.router.js";
import codingRouter from "./routers/coding.router.js";
configDotenv();
const app = express();
const PORT = process.env.PORT;
const MONGODB_URI = process.env.MONGODB_URI;
var corsOptions = {
origin: 'http://localhost:3000',
credentials: true,
optionsSuccessStatus: 200
}
app.use(cors(corsOptions));
app.use(cookieParser());
app.use(express.json());
app.get('/', (req, res) => res.json({ status: "Running" }));
app.use('/auth', authRouter);
app.use('/', bookmarkRouter);
app.use('/', codingRouter);
mongoose.connect(MONGODB_URI)
.then(() => {
console.log("Connected to DataBase");
app.listen(PORT, () => { console.log(`Server listening on port ${PORT}`); });
})
.catch(() => {
console.log("Cannot connect to database");
return;
});