Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 9acf9cb

Browse files
authored
Return runtime entry URL from Miniflare#ready (#396)
* Resolve `Miniflare#ready` with runtime entry URL * Remove `startServer()` This was a breaking change anyway, as we no longer return an `http.Server`. Given it's just an alias for `ready`, and doesn't actually start a server, it doesn't make much sense to keep it. * Use service name not binding name as service binding designator This was a mistake and prevented service bindings being bound with different names to the corresponding bound workers.
1 parent 69a4a07 commit 9acf9cb

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

packages/tre/src/index.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@ import exitHook from "exit-hook";
44
import getPort from "get-port";
55
import { bold, green, grey } from "kleur/colors";
66
import stoppable from "stoppable";
7-
import { RequestInfo, RequestInit, fetch } from "undici";
8-
import { HeadersInit, Request, Response } from "undici";
7+
import {
8+
HeadersInit,
9+
Request,
10+
RequestInfo,
11+
RequestInit,
12+
Response,
13+
fetch,
14+
} from "undici";
15+
import workerd from "workerd";
916
import { z } from "zod";
1017
import { setupCf } from "./cf";
1118

@@ -189,10 +196,6 @@ export class Miniflare {
189196
}
190197
}
191198

192-
startServer(): Promise<void> {
193-
return this.ready;
194-
}
195-
196199
async dispatchFetch(
197200
input: RequestInfo,
198201
init?: RequestInit
@@ -203,6 +206,7 @@ export class Miniflare {
203206
url.host = this.#runtimeEntryURL!.host;
204207
return fetch(url, forward as RequestInit);
205208
}
209+
206210
async #init() {
207211
// Start loopback server (how the runtime accesses with Miniflare's storage)
208212
this.#loopbackServer = await this.#startLoopbackServer(0, "127.0.0.1");
@@ -433,8 +437,11 @@ export class Miniflare {
433437
return { services, sockets };
434438
}
435439

436-
get ready() {
437-
return this.#initPromise;
440+
get ready(): Promise<URL> {
441+
// Cannot use async/await with getters.
442+
// Safety: `#runtimeEntryURL` is assigned in `#init()`. `#initPromise`
443+
// doesn't resolve until `#init()` returns.
444+
return this.#initPromise.then(() => this.#runtimeEntryURL!);
438445
}
439446

440447
#checkDisposed() {

packages/tre/src/plugins/core/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export const CORE_PLUGIN: Plugin<
194194
name:
195195
typeof service === "function"
196196
? `${SERVICE_CUSTOM_PREFIX}:${name}` // Custom `fetch` function
197-
: `${SERVICE_USER_PREFIX}:${name}`, // Regular user worker
197+
: `${SERVICE_USER_PREFIX}:${service}`, // Regular user worker
198198
},
199199
}))
200200
);

0 commit comments

Comments
 (0)