diff --git a/src/client/HostLobbyModal.ts b/src/client/HostLobbyModal.ts index aad7ff26a..308938cec 100644 --- a/src/client/HostLobbyModal.ts +++ b/src/client/HostLobbyModal.ts @@ -589,7 +589,7 @@ export class HostLobbyModal extends LitElement { private async putGameConfig() { const config = await getServerConfigFromClient(); const response = await fetch( - `${window.location.origin}/${config.workerPath(this.lobbyId)}/game/${this.lobbyId}`, + `${window.location.origin}/api/${config.workerPath(this.lobbyId)}/game/${this.lobbyId}`, { method: "PUT", headers: { @@ -615,7 +615,7 @@ export class HostLobbyModal extends LitElement { this.close(); const config = await getServerConfigFromClient(); const response = await fetch( - `${window.location.origin}/${config.workerPath(this.lobbyId)}/start_game/${this.lobbyId}`, + `${window.location.origin}/${config.workerPath(this.lobbyId)}/api/start_game/${this.lobbyId}`, { method: "POST", headers: { @@ -642,7 +642,7 @@ export class HostLobbyModal extends LitElement { private async pollPlayers() { const config = await getServerConfigFromClient(); - fetch(`/${config.workerPath(this.lobbyId)}/game/${this.lobbyId}`, { + fetch(`/${config.workerPath(this.lobbyId)}/api/game/${this.lobbyId}`, { method: "GET", headers: { "Content-Type": "application/json", @@ -661,7 +661,7 @@ async function createLobby(): Promise { try { const id = generateID(); const response = await fetch( - `/${config.workerPath(id)}/create_game/${id}`, + `/${config.workerPath(id)}/api/create_game/${id}`, { method: "POST", headers: { diff --git a/src/client/JoinPrivateLobbyModal.ts b/src/client/JoinPrivateLobbyModal.ts index 32c276bfd..324f2f364 100644 --- a/src/client/JoinPrivateLobbyModal.ts +++ b/src/client/JoinPrivateLobbyModal.ts @@ -361,7 +361,7 @@ export class JoinPrivateLobbyModal extends LitElement { this.message = "Checking lobby..."; // Set initial message const config = await getServerConfigFromClient(); - const url = `/${config.workerPath(lobbyId)}/game/${lobbyId}/exists`; + const url = `/${config.workerPath(lobbyId)}/api/game/${lobbyId}/exists`; fetch(url, { method: "GET", headers: { @@ -402,7 +402,7 @@ export class JoinPrivateLobbyModal extends LitElement { const config = await getServerConfigFromClient(); fetch( - `/${config.workerPath(this.lobbyIdInput.value)}/game/${this.lobbyIdInput.value}`, + `/${config.workerPath(this.lobbyIdInput.value)}/api/game/${this.lobbyIdInput.value}`, { method: "GET", headers: { diff --git a/src/client/LocalServer.ts b/src/client/LocalServer.ts index 099d6ca7c..8d2ac5f93 100644 --- a/src/client/LocalServer.ts +++ b/src/client/LocalServer.ts @@ -126,6 +126,6 @@ export class LocalServer { type: "application/json", }); const workerPath = this.serverConfig.workerPath(this.lobbyConfig.gameID); - navigator.sendBeacon(`/${workerPath}/archive_singleplayer_game`, blob); + navigator.sendBeacon(`/${workerPath}/api/archive_singleplayer_game`, blob); } } diff --git a/src/client/PublicLobby.ts b/src/client/PublicLobby.ts index 6fb5ef019..b443efecf 100644 --- a/src/client/PublicLobby.ts +++ b/src/client/PublicLobby.ts @@ -45,7 +45,7 @@ export class PublicLobby extends LitElement { async fetchLobbies(): Promise { try { - const response = await fetch(`/public_lobbies`); + const response = await fetch(`/api/public_lobbies`); if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`); const data = await response.json(); diff --git a/src/server/Master.ts b/src/server/Master.ts index 2b15eda53..6df862a29 100644 --- a/src/server/Master.ts +++ b/src/server/Master.ts @@ -137,7 +137,7 @@ app.get("/api/env", (req, res) => { }); // Add lobbies endpoint to list public games for this worker -app.get("/public_lobbies", (req, res) => { +app.get("/api/public_lobbies", (req, res) => { res.send(publicLobbiesJsonStr); }); @@ -146,7 +146,7 @@ async function fetchLobbies(): Promise { for (const gameID of publicLobbyIDs) { const port = config.workerPort(gameID); - const promise = fetch(`http://localhost:${port}/game/${gameID}`) + const promise = fetch(`http://localhost:${port}/api/game/${gameID}`) .then((resp) => resp.json()) .then((json) => { return json as GameInfo; @@ -209,7 +209,7 @@ async function schedulePublicGame() { // Send request to the worker to start the game try { const response = await fetch( - `http://localhost:${config.workerPort(gameID)}/create_game/${gameID}`, + `http://localhost:${config.workerPort(gameID)}/api/create_game/${gameID}`, { method: "POST", headers: { diff --git a/src/server/Worker.ts b/src/server/Worker.ts index 5f0d34bd5..03eb55afc 100644 --- a/src/server/Worker.ts +++ b/src/server/Worker.ts @@ -100,7 +100,7 @@ export function startWorker() { // Endpoint to create a private lobby app.post( - "/create_game/:id", + "/api/create_game/:id", asyncHandler(async (req, res) => { const id = req.params.id; if (!id) { @@ -137,7 +137,7 @@ export function startWorker() { // Add other endpoints from your original server app.post( - "/start_game/:id", + "/api/start_game/:id", asyncHandler(async (req, res) => { console.log(`starting private lobby with id ${req.params.id}`); const game = gm.game(req.params.id); @@ -157,7 +157,7 @@ export function startWorker() { ); app.put( - "/game/:id", + "/api/game/:id", asyncHandler(async (req, res) => { // TODO: only update public game if from local host const lobbyID = req.params.id; @@ -188,7 +188,7 @@ export function startWorker() { ); app.get( - "/game/:id/exists", + "/api/game/:id/exists", asyncHandler(async (req, res) => { const lobbyId = req.params.id; res.json({ @@ -198,7 +198,7 @@ export function startWorker() { ); app.get( - "/game/:id", + "/api/game/:id", asyncHandler(async (req, res) => { const game = gm.game(req.params.id); if (game == null) { @@ -210,7 +210,7 @@ export function startWorker() { ); app.post( - "/archive_singleplayer_game", + "/api/archive_singleplayer_game", asyncHandler(async (req, res) => { const gameRecord: GameRecord = req.body; const clientIP = req.ip || req.socket.remoteAddress || "unknown"; diff --git a/webpack.config.js b/webpack.config.js index fdf9e79ae..1e77454e8 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -187,14 +187,13 @@ export default (env, argv) => { { context: [ "/api/env", - "/public_lobbies", - "/join_game", - "/start_game", - "/create_game", - "/archive_singleplayer_game", - "/debug-ip", - "/auth/callback", - "/auth/discord", + "/api/public_lobbies", + "/api/join_game", + "/api/start_game", + "/api/create_game", + "/api/archive_singleplayer_game", + "/api/auth/callback", + "/api/auth/discord", ], target: "http://localhost:3000", secure: false,