From 615d8cf656c88fa3ebd6deceecf468338928815e Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Sun, 17 May 2020 14:45:34 -0700 Subject: [PATCH] empires: Serve the actual game file from the root of the app This game.html file is actually totally static, but it lives at a dynamic path (which includes the game ID in the path), so within the dynamic app we need to serve the static file. To arrange for this we symlink to the static file. Note that we're not committing the symlink to git since the destination location can differ on each system. --- .gitignore | 1 + empires.js | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/.gitignore b/.gitignore index 3c3629e..fa6e5f2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +game.html diff --git a/empires.js b/empires.js index 20dfa78..593598a 100644 --- a/empires.js +++ b/empires.js @@ -1,6 +1,7 @@ const express = require("express"); const cors = require("cors"); const body_parser = require("body-parser"); +const path = require("path"); const app = express(); app.use(cors()); @@ -249,6 +250,10 @@ function handle_events(request, response) { }); } +app.get('/', (request, response) => { + response.sendFile(path.join(__dirname, './game.html')); +}); + app.post('/register', (request, response) => { const game = request.game; game.add_player(request.body.name, request.body.character); -- 2.43.0