-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
30 lines (23 loc) · 799 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
const express = require("express");
const http = require("http");
const path = require("path");
const { connect } = require("./lib/db");
const { getGameById } = require("./lib/routes");
const { listenSocket } = require("./lib/socket");
const app = express();
const server = http.createServer(app);
const PORT = process.env.PORT || 8080;
const MONGODB_URI =
process.env.MONGODB_URI || "mongodb://localhost:27017/dev-scribble";
listenSocket(server);
app.get("/api/games/:gameId", getGameById);
app.use(express.static(path.join(__dirname, "build")));
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "build", "index.html"));
});
connect(MONGODB_URI).then(() => {
console.log("DB connected");
server.listen(PORT, () => {
console.log(`listening on *:${PORT}`);
});
});