forked from Kibble/online-coup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
36 lines (31 loc) · 1.08 KB
/
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
33
34
35
36
// from boardgame.io guide for Deployment to Heroku of Frontend and Backend
import { Server, FlatFile } from "boardgame.io/server";
import { Coup } from "./src/Game/Game";
import { nanoid, customAlphabet } from "nanoid";
import path from "path";
import serve from "koa-static";
import { DEFAULT_PORT } from "./src/config";
const server = Server({
games: [Coup],
db: new FlatFile({ dir: "db", logging: false, ttl: 1000 * 60 * 60 }),
});
const PORT = process.env.PORT || DEFAULT_PORT;
// build path relative to the server.js file
const frontEndAppBuildPath = path.resolve(__dirname, "./build");
server.app.use(serve(frontEndAppBuildPath));
// server.run(PORT, () => {
// server.app.use(
// async (ctx, next) => await serve(frontEndAppBuildPath)(Object.assign(ctx, { path: "index.html" }), next)
// );
// });
server.run({
port: PORT,
callback: () => {
server.app.use(
async (ctx, next) => await serve(frontEndAppBuildPath)(Object.assign(ctx, { path: "index.html" }), next)
);
},
lobbyConfig: {
uuid: customAlphabet("ABCDEFGHJKMNOPQRSTUVWXYZ0123456789", 6),
},
});