forked from dawhisky/dawhisky-BE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
66 lines (55 loc) · 1.58 KB
/
app.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
const express = require("express");
const app = express();
const cookieParser = require("cookie-parser");
const { host, sentry } = require("./config/config");
const port = host.port;
const cors = require("cors");
const errorHandler = require("./middlewares/error-handler");
const Sentry = require("@sentry/node");
const swaggerUi = require("swagger-ui-express");
const swaggerFile = require("./swagger-output");
require("express-async-errors");
app.use(express.static("public"));
//chat1
const socket = require("socket.io");
const server = app.listen(port, () => {
console.log(`running http://localhost:${port}`);
});
const io = socket(server, { path: "/socket.io" });
// parser
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.use(cookieParser());
// sentry
Sentry.init({
dsn: sentry.dsn,
tracesSampleRate: 1.0,
});
app.use(Sentry.Handlers.requestHandler());
app.use(Sentry.Handlers.tracingHandler());
app.use(Sentry.Handlers.errorHandler());
// cors
app.use(
cors({
origin: [
"http://localhost:3000",
"http://52.78.56.220:3000",
"https://www.dawhisky.com",
"https://dawhisky-fe.vercel.app",
"https://dawhisky-test.vercel.app",
"https://dawhisky-pwa.vercel.app",
],
credentials: "true",
})
);
// router
const apiMainRouter = require("./routes/index");
app.use("/api", [apiMainRouter]);
// errorHandler
app.use(errorHandler);
// swagger
app.use("/api/swag", swaggerUi.serve, swaggerUi.setup(swaggerFile));
//chat2
const socketHandler = require("./modules/socket-handler");
socketHandler(io);
module.exports = app;