Skip to content

Commit 9eb8bdc

Browse files
committed
Compare origin against WEBSITE_BASE
1 parent 7733724 commit 9eb8bdc

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

src/utils/respond.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export const withCache = (ctx: Context, age: number, immutable = false) => {
7777
* @param ctx Request context.
7878
*/
7979
export const isWebsite = (ctx: Context) =>
80-
env.WEBSITE_BASE && ctx.req.url.startsWith(env.WEBSITE_BASE);
80+
env.WEBSITE_BASE && new URL(ctx.req.url).origin === env.WEBSITE_BASE;
8181

8282
/**
8383
* Respond to a request with data, handling if it should be returned as JSON or rendered as a React response.

src/utils/spec/playwright.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ import { test as base, expect } from '@playwright/test';
22
import { type TestHarness, createTestHarness } from 'wrangler';
33

44
const configPath = './wrangler.jsonc';
5-
// isWebsite() uses startsWith(), so the trailing colon matches every
6-
// dynamically allocated loopback port without matching another host.
7-
const websiteBase = 'http://127.0.0.1:';
85

96
interface TestFixtures {
107
reset: undefined;
@@ -19,7 +16,7 @@ export const createServer = (vars?: Record<string, string>) =>
1916
workers: [
2017
{
2118
configPath,
22-
vars: { WEBSITE_BASE: websiteBase, ...vars },
19+
vars,
2320
},
2421
],
2522
});
@@ -55,7 +52,24 @@ export const test = base.extend<TestFixtures, WorkerFixtures>({
5552
}
5653

5754
const { url } = await server.listen();
58-
await use(url.href);
55+
const { WEBSITE_BASE } = await server.getWorker().getEnv();
56+
if (WEBSITE_BASE !== url.origin) {
57+
await server.update((opts) => {
58+
const worker = opts.workers[0];
59+
if (!worker || !('vars' in worker)) {
60+
throw new Error('Worker not found in test harness');
61+
}
62+
63+
worker.vars = {
64+
...worker.vars,
65+
WEBSITE_BASE: url.origin,
66+
};
67+
68+
return opts;
69+
});
70+
}
71+
72+
await use(url.origin);
5973
},
6074
reset: [
6175
async ({ server }, use, testInfo) => {

0 commit comments

Comments
 (0)