-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
50 lines (44 loc) · 1.19 KB
/
server.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
const express = require("express");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const cors = require("cors");
const cookieParser = require("cookie-parser");
const dotenv = require("dotenv");
dotenv.config();
const userRoute = require("./routes/auth");
const postRoute = require("./routes/post");
const subsRoute = require("./routes/subs");
const app = express();
app.use(bodyParser.json({ limit: "30mb", extended: true }));
app.use(bodyParser.urlencoded({ limit: "30mb", extended: true }));
// app.set("trust proxy", 1);
app.use(cookieParser());
app.use(
cors({
credentials: true,
origin: [
"https://reddit-react.vercel.app",
"http://localhost:3000",
"/.vercel\.app$/",
],
// origin: "*",
optionsSuccessStatus: 200,
})
);
app.use(express.static("public"));
app.use("/api/auth", userRoute);
app.use("/api/post", postRoute);
app.use("/api/subs", subsRoute);
mongoose
.connect(process.env.MONGOOSE, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() =>
app.listen(process.env.PORT, () => {
console.log(`running on ${process.env.PORT}`);
})
)
.catch((err) => {
console.log(err);
});