-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathserver.js
32 lines (26 loc) · 945 Bytes
/
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
const { app, http } = require("./serverConfig");
const express = require("express");
const bodyParser = require("body-parser");
const cors = require("cors");
const SocketLobby = require("./socket/socket");
// middleware setup
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(__dirname + "/client/build"));
// serve react app (after build)
app.get("/", (req, res) => {
res.sendFile(__dirname + "/client/build/index.html");
});
app.get("/create-lobby", (req, res) => {
const newLobby = new SocketLobby();
res.json({ lobbyNum: newLobby.getLobbyNum() });
});
app.get("/lobby/:lobbyNum/download/:fileName", (req, res) => {
const { lobbyNum, fileName } = req.params;
const filePath = __dirname + "/temporary/lobby-" + lobbyNum + "/" + fileName;
res.download(filePath);
});
http.listen(process.env.PORT || 8000, () => {
console.log("connected to server");
});