diff --git a/design/src/compare.ts b/design/src/compare.ts index 547c85558..cd1be0ab6 100644 --- a/design/src/compare.ts +++ b/design/src/compare.ts @@ -391,6 +391,17 @@ export function generateCompareHtml(images: string[]): string {
\n`, - ); - return new Response(injected, { + return new Response(htmlContent, { headers: { "Content-Type": "text/html; charset=utf-8" }, }); } diff --git a/design/test/feedback-roundtrip.test.ts b/design/test/feedback-roundtrip.test.ts index cd757f38b..e8d63db23 100644 --- a/design/test/feedback-roundtrip.test.ts +++ b/design/test/feedback-roundtrip.test.ts @@ -55,7 +55,7 @@ beforeAll(async () => { serverState = 'serving'; // This server mirrors the real serve.ts behavior: - // - Injects __GSTACK_SERVER_URL into the HTML + // - Serves board HTML at / (board JS uses relative URLs) // - Handles POST /api/feedback with file writes // - Handles GET /api/progress for regeneration polling // - Handles POST /api/reload for board swapping @@ -67,11 +67,7 @@ beforeAll(async () => { const url = new URL(req.url); if (req.method === 'GET' && (url.pathname === '/' || url.pathname === '/index.html')) { - const injected = currentHtml.replace( - '', - `\n` - ); - return new Response(injected, { + return new Response(currentHtml, { headers: { 'Content-Type': 'text/html; charset=utf-8' }, }); } @@ -140,14 +136,15 @@ describe('Submit: browser click → feedback.json on disk', () => { if (fs.existsSync(feedbackPath)) fs.unlinkSync(feedbackPath); serverState = 'serving'; - // Navigate to the board (served with __GSTACK_SERVER_URL injected) + // Navigate to the board (board JS uses relative URLs + location.protocol detect) await handleWriteCommand('goto', [baseUrl], bm); - // Verify __GSTACK_SERVER_URL was injected - const hasServerUrl = await handleReadCommand('js', [ - '!!window.__GSTACK_SERVER_URL' + // Verify the board detects HTTP mode (so postFeedback will actually fetch + // instead of falling into the file:// DOM-only path) + const httpDetected = await handleReadCommand('js', [ + "location.protocol === 'http:' || location.protocol === 'https:'" ], bm); - expect(hasServerUrl).toBe('true'); + expect(httpDetected).toBe('true'); // User picks variant A, rates it 5 stars await handleReadCommand('js', [ diff --git a/design/test/serve.test.ts b/design/test/serve.test.ts index f222a6364..d3a30bcdc 100644 --- a/design/test/serve.test.ts +++ b/design/test/serve.test.ts @@ -65,11 +65,9 @@ describe('Serve HTTP endpoints', () => { const url = new URL(req.url); if (req.method === 'GET' && url.pathname === '/') { - const injected = htmlContent.replace( - '', - `\n` - ); - return new Response(injected, { + // Board JS uses relative URLs (./api/feedback, ./api/progress) + // and a location.protocol feature-detect; no injection needed. + return new Response(htmlContent, { headers: { 'Content-Type': 'text/html; charset=utf-8' }, }); } @@ -118,12 +116,17 @@ describe('Serve HTTP endpoints', () => { server.stop(); }); - test('GET / serves HTML with injected __GSTACK_SERVER_URL', async () => { + test('GET / serves HTML with relative-path board JS (no injection)', async () => { const res = await fetch(baseUrl); expect(res.status).toBe(200); const html = await res.text(); - expect(html).toContain('__GSTACK_SERVER_URL'); - expect(html).toContain(baseUrl); + // No more per-origin URL injection; board JS uses relative paths. + expect(html).not.toContain('__GSTACK_SERVER_URL'); + expect(html).not.toContain(baseUrl); + // Board JS calls relative endpoints so the same HTML works at / and at + // /boards/