-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (42 loc) · 1.15 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
52
53
54
require("dotenv").config();
const express = require("express");
const app = express();
const port = process.env.PORT || 5000;
const router = require("./src/routers");
const cors = require("cors");
const http = require("http");
const { Server } = require("socket.io");
const httpServer = http.createServer(app);
app.use(express.json());
// Enable this for local dev
// app.use(cors());
const corsConf = {
origin: process.env.FE_ORIGIN,
credentials: true,
optionsSuccessStatus: 200,
methods: ["GET", "OPTIONS", "PATCH", "DELETE", "POST", "PUT"],
};
app.use(cors(corsConf));
app.options(process.env.FE_ORIGIN, cors(corsConf));
// For manual payment, store at local
// app.use("/img", express.static("./uploads/img"));
// Default route
app.get("/", function (_req, res) {
res.send({
message: "check ok!",
});
});
// API route
app.use("/api/v1/", router);
httpServer.listen(port, () => {
console.info(`listen port ${port}`);
});
// WSS init
const io = new Server(httpServer, {
cors: {
origin: `${process.env.FE_ORIGIN}`,
credentials: true, // Disable this for local dev
methods: ["GET", "POST"],
},
});
require("./src/socket")(io);