-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
74 lines (61 loc) · 2.23 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const express = require("express");
const session = require("cookie-session");
const cors = require("cors");
const cookieParser = require("cookie-parser");
const bodyParser = require("body-parser");
const cloudinary = require("cloudinary");
const path = require("path");
const imageRoutes = require("./routes/imageRoutes");
const salePostRoutes = require("./routes/salePostRoutes");
const myPageRoute = require("./routes/myPageRoutes");
const authRoutes = require("./routes/authRoutes");
const campsiteRoutes = require("./routes/campsiteRoutes");
const blogPostRoutes = require("./routes/blogPostRoutes");
const messageRoutes = require("./routes/messageRoutes");
const checkoutRoutes = require("./routes/checkoutRoutes");
const { app, server } = require("./utils/socket");
const { scheduleCouponExpirationCheck } = require("./utils/cron");
const db = require("./db/connectDB");
require("dotenv").config();
const port = process.env.PORT_NUM || 8000;
const clientPort = process.env.CLIENT_PORT_NUM || 3000;
cloudinary.config({
cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
api_key: process.env.CLOUDINARY_API_KEY,
api_secret: process.env.CLOUDINARY_API_SECRET,
});
// app.use(cors({ credentials: true, origin: `${process.env.CLIENT_URL}` }));
// app.use(cors({ credentials: true, origin: `http://localhost:${clientPort}` }));
app.use(
session({
secret: "your session secret",
resave: false,
saveUninitialized: true,
cookie: { secure: false },
})
);
let corsOptions = {
origin: `${process.env.CLIENT_URL}`,
// origin: `http://localhost:${clientPort}`,
credentials: true,
};
app.use(cors(corsOptions));
app.use(express.json());
app.use(cookieParser());
app.use(bodyParser.json());
app.use(
"/api/images",
express.static(path.join(__dirname, "../client/src/image/EventImage"))
);
app.use("/api", imageRoutes);
app.use("/api/sale-posts", salePostRoutes);
app.use("/api/blog-posts", blogPostRoutes);
app.use("/api/messages", messageRoutes);
app.use("/", myPageRoute);
app.use("/", authRoutes);
app.use("/", campsiteRoutes);
app.use("/api/checkout", checkoutRoutes);
db.connectDB();
app.get("/", async (req, res) => res.json("Hello World!"));
scheduleCouponExpirationCheck();
server.listen(port, () => console.log(`${port}번에서 돌아감`));