Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/warm-foxes-shave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"miniflare": patch
---

Remove `LOCAL_EXPLORER_BASE_PATH` and `LOCAL_EXPLORER_API_PATH` constants in favor of `CorePaths.EXPLORER`

These were redundant aliases introduced before `CorePaths` was centralized. All internal consumers now use `CorePaths.EXPLORER` directly.
36 changes: 15 additions & 21 deletions fixtures/worker-with-resources/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { resolve } from "path";
import { LOCAL_EXPLORER_API_PATH, LOCAL_EXPLORER_BASE_PATH } from "miniflare";
import { CorePaths } from "miniflare";
import { afterAll, assert, beforeAll, describe, it } from "vitest";
import { runWranglerDev } from "../../shared/src/run-wrangler-long-lived";

const EXPLORER_API_PATH = `${CorePaths.EXPLORER}/api`;

describe("local explorer", () => {
let ip: string;
let port: number;
Expand All @@ -19,11 +21,11 @@ describe("local explorer", () => {
await stop?.();
});

it(`returns local explorer API response for ${LOCAL_EXPLORER_API_PATH}`, async ({
it(`returns local explorer API response for ${EXPLORER_API_PATH}`, async ({
expect,
}) => {
const response = await fetch(
`http://${ip}:${port}${LOCAL_EXPLORER_API_PATH}/storage/kv/namespaces`
`http://${ip}:${port}${EXPLORER_API_PATH}/storage/kv/namespaces`
);
expect(response.headers.get("Content-Type")).toBe("application/json");
const json = await response.json();
Expand Down Expand Up @@ -53,12 +55,8 @@ describe("local explorer", () => {
expect(text).toBe("Hello World!");
});

it(`serves UI index.html at ${LOCAL_EXPLORER_BASE_PATH}`, async ({
expect,
}) => {
const response = await fetch(
`http://${ip}:${port}${LOCAL_EXPLORER_BASE_PATH}`
);
it(`serves UI index.html at ${CorePaths.EXPLORER}`, async ({ expect }) => {
const response = await fetch(`http://${ip}:${port}${CorePaths.EXPLORER}`);
expect(response.status).toBe(200);
expect(response.headers.get("Content-Type")).toBe(
"text/html; charset=utf-8"
Expand All @@ -68,12 +66,12 @@ describe("local explorer", () => {
expect(text).toContain("Cloudflare Local Explorer");
});

it(`serves UI assets at ${LOCAL_EXPLORER_BASE_PATH}/assets/*`, async ({
it(`serves UI assets at ${CorePaths.EXPLORER}/assets/*`, async ({
expect,
}) => {
// First get index.html to find the actual asset paths
const indexResponse = await fetch(
`http://${ip}:${port}${LOCAL_EXPLORER_BASE_PATH}`
`http://${ip}:${port}${CorePaths.EXPLORER}`
);
const html = await indexResponse.text();

Expand All @@ -85,7 +83,7 @@ describe("local explorer", () => {

// Fetch the JS asset
const jsResponse = await fetch(
`http://${ip}:${port}${LOCAL_EXPLORER_BASE_PATH}/${jsPath}`
`http://${ip}:${port}${CorePaths.EXPLORER}/${jsPath}`
);
expect(jsResponse.status).toBe(200);
expect(jsResponse.headers.get("Content-Type")).toMatch(
Expand All @@ -96,7 +94,7 @@ describe("local explorer", () => {
it("serves UI with SPA fallback for unknown routes", async ({ expect }) => {
// Request a route that doesn't exist as a file but should be handled by the SPA
const response = await fetch(
`http://${ip}:${port}${LOCAL_EXPLORER_BASE_PATH}/kv/some-namespace`
`http://${ip}:${port}${CorePaths.EXPLORER}/kv/some-namespace`
);
expect(response.status).toBe(200);
expect(response.headers.get("Content-Type")).toBe(
Expand All @@ -123,12 +121,10 @@ describe("local explorer", () => {
await stop?.();
});

it("returns worker response for LOCAL_EXPLORER_API_PATH", async ({
it(`returns worker response for ${EXPLORER_API_PATH}`, async ({
expect,
}) => {
const response = await fetch(
`http://${ip}:${port}${LOCAL_EXPLORER_API_PATH}`
);
const response = await fetch(`http://${ip}:${port}${EXPLORER_API_PATH}`);
const text = await response.text();
expect(text).toBe("Hello World!");
});
Expand Down Expand Up @@ -171,7 +167,7 @@ describe("local explorer", () => {
expect,
}) => {
const response = await fetch(
`http://${ip}:${port}${LOCAL_EXPLORER_API_PATH}/storage/kv/namespaces`
`http://${ip}:${port}${EXPLORER_API_PATH}/storage/kv/namespaces`
);
expect(response.status).toBe(200);
expect(response.headers.get("Content-Type")).toBe("application/json");
Expand All @@ -180,9 +176,7 @@ describe("local explorer", () => {
});

it(`serves explorer UI`, async ({ expect }) => {
const response = await fetch(
`http://${ip}:${port}${LOCAL_EXPLORER_BASE_PATH}`
);
const response = await fetch(`http://${ip}:${port}${CorePaths.EXPLORER}`);
expect(response.status).toBe(200);
expect(response.headers.get("Content-Type")).toBe(
"text/html; charset=utf-8"
Expand Down
5 changes: 0 additions & 5 deletions packages/miniflare/src/plugins/core/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { CorePaths } from "../../workers";
import type {
DoRawQueryResult,
DoSqlWithParams,
Expand All @@ -12,10 +11,6 @@ export const SERVICE_ENTRY = `${CORE_PLUGIN_NAME}:entry`;
export const SERVICE_LOCAL_EXPLORER = `${CORE_PLUGIN_NAME}:local-explorer`;
// Disk service for local explorer UI assets
export const LOCAL_EXPLORER_DISK = `${CORE_PLUGIN_NAME}:local-explorer-disk`;
// URL path prefix where the local explorer UI is served
export const LOCAL_EXPLORER_BASE_PATH = CorePaths.EXPLORER;
// URL path prefix for the local explorer API endpoints
export const LOCAL_EXPLORER_API_PATH = `${CorePaths.EXPLORER}/api`;
// Service prefix for all regular user workers
const SERVICE_USER_PREFIX = `${CORE_PLUGIN_NAME}:user`;
// Service prefix for `workerd`'s builtin services (network, external, disk)
Expand Down
2 changes: 0 additions & 2 deletions packages/miniflare/src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,6 @@ export {
CORE_PLUGIN,
CORE_PLUGIN_NAME,
SERVICE_ENTRY,
LOCAL_EXPLORER_BASE_PATH,
LOCAL_EXPLORER_API_PATH,
CoreOptionsSchema,
CoreSharedOptionsSchema,
compileModuleRules,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
* any one instance can aggregate data from all instances.
*/

import { LOCAL_EXPLORER_API_PATH } from "../../plugins/core/constants";
import { CorePaths } from "../core";
import type { WorkerRegistry } from "../../shared/dev-registry-types";
import type { AppContext } from "./common";

const EXPLORER_API_PATH = `${CorePaths.EXPLORER}/api`;

/**
* Header that indicates a request should not trigger further aggregation.
* Used to prevent infinite recursion when instance A fetches from instance B.
Expand Down Expand Up @@ -60,7 +62,7 @@ export async function fetchFromPeer(
init?: RequestInit
): Promise<Response | null> {
try {
const url = new URL(`${LOCAL_EXPLORER_API_PATH}${apiPath}`, peerUrl);
const url = new URL(`${EXPLORER_API_PATH}${apiPath}`, peerUrl);
const response = await fetch(url.toString(), {
...init,
headers: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@

import { Hono } from "hono/tiny";
import mime from "mime";
import {
LOCAL_EXPLORER_API_PATH,
LOCAL_EXPLORER_BASE_PATH,
} from "../../plugins/core/constants";
import { CoreBindings } from "../core";
import { CoreBindings, CorePaths } from "../core";
import { errorResponse, validateQuery, validateRequestBody } from "./common";
import { wrapResponse } from "./common";
import {
Expand Down Expand Up @@ -56,7 +52,9 @@ export type Env = {

export type AppBindings = { Bindings: Env };

const app = new Hono<AppBindings>().basePath(LOCAL_EXPLORER_BASE_PATH);
const EXPLORER_API_PATH = `${CorePaths.EXPLORER}/api`;

const app = new Hono<AppBindings>().basePath(CorePaths.EXPLORER);

// Global error handler - catches all uncaught errors and wraps them in an error response
app.onError((err) => {
Expand Down Expand Up @@ -109,14 +107,13 @@ function getContentType(filePath: string): string {
}

app.get("/*", async (c, next) => {
if (c.req.path.startsWith(LOCAL_EXPLORER_API_PATH)) {
if (c.req.path.startsWith(EXPLORER_API_PATH)) {
// continue on to API routes
return next();
}

// Some simple asset path handling...
let assetPath =
c.req.path.replace(LOCAL_EXPLORER_BASE_PATH, "") || "/index.html";
let assetPath = c.req.path.replace(CorePaths.EXPLORER, "") || "/index.html";
if (assetPath === "/") {
assetPath = "/index.html";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import path from "node:path";
import { removeDirSync } from "@cloudflare/workers-utils";
import { getWorkerRegistry, Miniflare } from "miniflare";
import { afterAll, beforeAll, describe, test } from "vitest";
import { LOCAL_EXPLORER_API_PATH } from "../../../src/plugins/core/constants";
import { CorePaths } from "../../../src/workers/core/constants";
import { disposeWithRetry } from "../../test-shared";

const BASE_URL = `http://localhost${LOCAL_EXPLORER_API_PATH}`;
const BASE_URL = `http://localhost${CorePaths.EXPLORER}/api`;

/**
* Poll the dev registry until all expected workers are registered.
Expand Down
4 changes: 2 additions & 2 deletions packages/miniflare/test/plugins/local-explorer/d1.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Miniflare } from "miniflare";
import { afterAll, beforeAll, describe, test } from "vitest";
import { LOCAL_EXPLORER_API_PATH } from "../../../src/plugins/core/constants";
import { CorePaths } from "../../../src/workers/core/constants";
import {
zD1ApiResponseCommonFailure,
zD1ListDatabasesResponse,
Expand All @@ -9,7 +9,7 @@ import {
import { disposeWithRetry } from "../../test-shared";
import { expectValidResponse } from "./helpers";

const BASE_URL = `http://localhost${LOCAL_EXPLORER_API_PATH}`;
const BASE_URL = `http://localhost${CorePaths.EXPLORER}/api`;

describe("D1 API", () => {
let mf: Miniflare;
Expand Down
4 changes: 2 additions & 2 deletions packages/miniflare/test/plugins/local-explorer/do.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from "node:path";
import { removeDir } from "@cloudflare/workers-utils";
import { Miniflare } from "miniflare";
import { afterAll, beforeAll, describe, test } from "vitest";
import { LOCAL_EXPLORER_API_PATH } from "../../../src/plugins/core/constants";
import { CorePaths } from "../../../src/workers/core/constants";
import { disposeWithRetry, useTmp } from "../../test-shared";

interface DONamespace {
Expand Down Expand Up @@ -40,7 +40,7 @@ interface ListObjectsResponse {
messages: Array<{ code: number; message: string }>;
}

const BASE_URL = `http://localhost${LOCAL_EXPLORER_API_PATH}`;
const BASE_URL = `http://localhost${CorePaths.EXPLORER}/api`;

describe("Durable Objects API", () => {
let mf: Miniflare;
Expand Down
10 changes: 5 additions & 5 deletions packages/miniflare/test/plugins/local-explorer/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import http from "node:http";
import { Miniflare } from "miniflare";
import { afterAll, beforeAll, describe, test } from "vitest";
import { LOCAL_EXPLORER_API_PATH } from "../../../src/plugins/core/constants";
import { CorePaths } from "../../../src/workers/core/constants";
import { disposeWithRetry } from "../../test-shared";

const BASE_URL = `http://localhost${LOCAL_EXPLORER_API_PATH}`;
const BASE_URL = `http://localhost${CorePaths.EXPLORER}/api`;

describe("Local Explorer API validation", () => {
let mf: Miniflare;
Expand Down Expand Up @@ -234,7 +234,7 @@ describe("Local Explorer API validation", () => {
const url = await mf.ready;
const status = await new Promise<number>((resolve, reject) => {
const req = http.get(
`${url.origin}${LOCAL_EXPLORER_API_PATH}/storage/kv/namespaces`,
`${url.origin}${CorePaths.EXPLORER}/api/storage/kv/namespaces`,
{ setHost: false, headers: { Host: "evil.com" } },
(res) => {
res.resume();
Expand Down Expand Up @@ -333,7 +333,7 @@ describe("Local Explorer works with custom routes", () => {
const url = await mf.ready;
const status = await new Promise<number>((resolve, reject) => {
const req = http.get(
`${url.origin}${LOCAL_EXPLORER_API_PATH}/storage/kv/namespaces`,
`${url.origin}${CorePaths.EXPLORER}/api/storage/kv/namespaces`,
{ setHost: false, headers: { Host: "my-custom-site.com" } },
(res) => {
res.resume();
Expand All @@ -351,7 +351,7 @@ describe("Local Explorer works with custom routes", () => {
const url = await mf.ready;
const status = await new Promise<number>((resolve, reject) => {
const req = http.get(
`${url.origin}${LOCAL_EXPLORER_API_PATH}/storage/kv/namespaces`,
`${url.origin}${CorePaths.EXPLORER}/api/storage/kv/namespaces`,
{ setHost: false, headers: { Host: "evil.com" } },
(res) => {
res.resume();
Expand Down
4 changes: 2 additions & 2 deletions packages/miniflare/test/plugins/local-explorer/kv.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Miniflare } from "miniflare";
import { afterAll, beforeAll, describe, test } from "vitest";
import { LOCAL_EXPLORER_API_PATH } from "../../../src/plugins/core/constants";
import { CorePaths } from "../../../src/workers/core/constants";
import {
zWorkersKvNamespaceDeleteKeyValuePairResponse,
zWorkersKvNamespaceGetMultipleKeyValuePairsResponse,
Expand All @@ -11,7 +11,7 @@ import {
import { disposeWithRetry } from "../../test-shared";
import { expectValidResponse } from "./helpers";

const BASE_URL = `http://localhost${LOCAL_EXPLORER_API_PATH}`;
const BASE_URL = `http://localhost${CorePaths.EXPLORER}/api`;

describe("KV API", () => {
let mf: Miniflare;
Expand Down
4 changes: 2 additions & 2 deletions packages/miniflare/test/plugins/local-explorer/r2.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Miniflare } from "miniflare";
import { afterAll, beforeAll, describe, test } from "vitest";
import { LOCAL_EXPLORER_API_PATH } from "../../../src/plugins/core/constants";
import { CorePaths } from "../../../src/workers/core/constants";
import {
zR2BucketDeleteObjectsResponse,
zR2BucketGetObjectResponse,
Expand All @@ -11,7 +11,7 @@ import {
import { disposeWithRetry } from "../../test-shared";
import { expectValidResponse } from "./helpers";

const BASE_URL = `http://localhost${LOCAL_EXPLORER_API_PATH}`;
const BASE_URL = `http://localhost${CorePaths.EXPLORER}/api`;

describe("R2 API", () => {
let mf: Miniflare;
Expand Down
4 changes: 2 additions & 2 deletions packages/wrangler/src/dev/hotkeys.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { generateContainerBuildId } from "@cloudflare/containers-shared";
import { LOCAL_EXPLORER_BASE_PATH } from "miniflare";
import { CorePaths } from "miniflare";
import { LocalRuntimeController } from "../api/startDevWorker/LocalRuntimeController";
import registerHotKeys from "../cli-hotkeys";
import { logger } from "../logger";
Expand Down Expand Up @@ -52,7 +52,7 @@ export default function registerDevHotKeys(
// label: "open local explorer",
handler: async () => {
const { url } = await primaryDevEnv.proxy.ready.promise;
const explorerUrl = new URL(LOCAL_EXPLORER_BASE_PATH, url);
const explorerUrl = new URL(CorePaths.EXPLORER, url);
await openInBrowser(explorerUrl.href);
},
},
Expand Down
Loading