-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
65 lines (58 loc) · 1.54 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
import * as path from "path";
import "./config/config.js";
import express from "express";
import cors from "cors";
import bodyParser from "body-parser";
import morgan from "morgan";
import { createServer } from "http";
import { Server } from "socket.io";
import code from "./socket/code.js";
import chat from "./socket/chat.js";
import scribble from "./socket/scribble.js";
import piston from "./routes/piston.js";
import room from "./routes/room.js";
import token from "./routes/token.js";
import './config/mongo.js'
const app = express();
app.use(morgan("dev"));
// const corsOptions = {
// origin: '*'
// }
// app.use(cors(corsOptions))
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(cors());
app.use(express.json());
app.use(
express.urlencoded({
extended: true,
})
);
const httpServer = createServer(app);
const io = new Server(httpServer, {
cors: {
origins: ["*"],
methods: ["GET", "POST"],
transports: ["websocket", "polling"],
credentials: true,
},
allowEIO3: true,
});
//const io = new Server(httpServer);
code(io);
chat(io);
scribble(io);
app.use("/room", room);
app.use("/code", piston);
app.use("/call", token);
if (process.env.NODE_ENV == "production") {
app.use(express.static("./client/build"));
app.get("*", (req, res) => {
const dirname = path.resolve(path.dirname(''));
res.sendFile(path.resolve(dirname, "client", "build", "index.html"));
});
}
const port = process.env.PORT || 4001;
httpServer.listen(port, () => {
console.log(`listening to ${port}`);
});