-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (43 loc) · 1.18 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 dotenv from "dotenv";
import cors from "cors";
import morgan from "morgan";
import bodyParser from "body-parser";
import helmet from "helmet";
import cookieParser from "cookie-parser";
import mongoose from "mongoose";
/* ROUTES */
import authRouter from "./routes/authRoutes.js";
import postRouter from "./routes/postRoutes.js";
import userRouter from "./routes/userRoutes.js";
dotenv.config();
const PORT = process.env.PORT || 8800;
const app = express();
mongoose.connect(process.env.DATABASE_URL).then(
() => {
console.log("Connected to MongoDB");
},
(err) => {
console.log("Error connecting to MongoDB: ", err);
}
);
app.use(helmet());
app.use(
cors({
credentials: true,
origin: process.env.REACT_APP_URL,
})
);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(morgan("dev"));
app.get("/", (req, res) => res.json("ok"));
app.use("/auth", authRouter);
app.use("/post", postRouter);
app.use("/users",userRouter);
app.listen(PORT, () => {
console.log(`Server running on port: ${PORT}`);
});