use api prefix

This commit is contained in:
Evan
2025-03-05 18:04:22 -08:00
parent d2dd262220
commit 3a0bc594ae
7 changed files with 24 additions and 25 deletions
+4 -4
View File
@@ -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<GameInfo> {
try {
const id = generateID();
const response = await fetch(
`/${config.workerPath(id)}/create_game/${id}`,
`/${config.workerPath(id)}/api/create_game/${id}`,
{
method: "POST",
headers: {
+2 -2
View File
@@ -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: {
+1 -1
View File
@@ -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);
}
}
+1 -1
View File
@@ -45,7 +45,7 @@ export class PublicLobby extends LitElement {
async fetchLobbies(): Promise<GameInfo[]> {
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();
+3 -3
View File
@@ -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<void> {
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: {
+6 -6
View File
@@ -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";
+7 -8
View File
@@ -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,