diff --git a/server/src/server/router/api/v1/games/_game/_playtype/content/bms-router.test.ts b/server/src/server/router/api/v1/games/_game/_playtype/content/bms-router.test.ts index c9e5ad953..049e7c837 100644 --- a/server/src/server/router/api/v1/games/_game/_playtype/content/bms-router.test.ts +++ b/server/src/server/router/api/v1/games/_game/_playtype/content/bms-router.test.ts @@ -1,11 +1,34 @@ +import { ServerConfig } from "lib/setup/config"; import t from "tap"; import mockApi from "test-utils/mock-api"; t.test("GET /api/v1/games/bms/7K/content/sieglindeEC", (t) => { + t.test("html compatibility return should point to the right file", async (t) => { + const res = await mockApi.get("/api/v1/games/bms/7K/content/sieglindeEC"); + + const content = //u.exec(res.text); + + if (content) { + const maybeMatch = content[1]; + + t.equal( + maybeMatch, + `${ServerConfig.OUR_URL}/api/v1/games/bms/7K/content/sieglindeEC/header.json` + ); + } else { + t.fail(`Didn't match regexp for having a bmstable header?`); + } + + t.end(); + }); + t.test("Should point to the right file.", async (t) => { const res = await mockApi.get("/api/v1/games/bms/7K/content/sieglindeEC/header.json"); - t.equal(res.body.data_url, "./body.json"); + t.equal( + res.body.data_url, + `${ServerConfig.OUR_URL}/api/v1/games/bms/7K/content/sieglindeEC/body.json` + ); t.end(); }); @@ -25,11 +48,13 @@ t.test("GET /api/v1/games/bms/7K/content/sieglindeHC", (t) => { t.test("Should point to the right file.", async (t) => { const res = await mockApi.get("/api/v1/games/bms/7K/content/sieglindeHC/header.json"); - t.equal(res.body.data_url, "./body.json"); + t.equal( + res.body.data_url, + `${ServerConfig.OUR_URL}/api/v1/games/bms/7K/content/sieglindeHC/body.json` + ); t.end(); }); - t.test("`body.json` should return an array.", async (t) => { const res = await mockApi.get("/api/v1/games/bms/7K/content/sieglindeHC/body.json"); diff --git a/server/src/server/router/api/v1/games/_game/_playtype/content/bms-router.ts b/server/src/server/router/api/v1/games/_game/_playtype/content/bms-router.ts index a52cbf25d..7f5015156 100644 --- a/server/src/server/router/api/v1/games/_game/_playtype/content/bms-router.ts +++ b/server/src/server/router/api/v1/games/_game/_playtype/content/bms-router.ts @@ -1,8 +1,10 @@ import { Router } from "express"; import db from "external/mongo/db"; import CreateLogCtx from "lib/logger/logger"; +import { ServerConfig } from "lib/setup/config"; import { CreateSongMap } from "tachi-common"; import { GetFolderCharts, GetFoldersFromTable } from "utils/folder"; +import path from "path"; import type { Request, Response } from "express"; import type { ChartDocument } from "tachi-common/types"; @@ -10,6 +12,13 @@ const logger = CreateLogCtx(__filename); const router: Router = Router({ mergeParams: true }); +function mkAbsoluteURL(tableName: string, headerOrBody: "body" | "header") { + return ( + ServerConfig.OUR_URL + + path.join("/api/v1/games/bms/7K/content/", tableName, `${headerOrBody}.json`) + ); +} + /** * Utility function for mounting a BMS-style Table. This defines * a header.json endpoint, and a body.json endpoint. @@ -24,9 +33,11 @@ function CreateAndMountTable( bodyHandler: (req: Request, res: Response) => unknown ) { router.get(`/${tableName}`, (req, res) => { + const ABS_URL = mkAbsoluteURL(tableName, "header"); + return res.status(200).send(` - + This is a stub page for the ${tableName} table. Go Home? `); @@ -49,7 +60,7 @@ CreateAndMountTable( return res.status(200).send({ name: "Sieglinde EC", symbol: "sgl-", - data_url: "./body.json", + data_url: mkAbsoluteURL("sieglindeEC", "body"), }); }, /* body.json */ async (req, res) => { @@ -111,7 +122,7 @@ CreateAndMountTable( return res.status(200).send({ name: "Sieglinde HC", symbol: "sgl-", - data_url: "./body.json", + data_url: mkAbsoluteURL("sieglindeHC", "body"), }); }, /* body.json */ async (req, res) => {