Skip to content

Commit 1cfb4bc

Browse files
authored
refactor: make App.prototype.handler() sync (#2906)
1 parent 9605cd8 commit 1cfb4bc

File tree

13 files changed

+49
-48
lines changed

13 files changed

+49
-48
lines changed

src/app.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,12 @@ export class App<State> {
243243
return this;
244244
}
245245

246-
async handler(): Promise<
247-
(request: Request, info?: Deno.ServeHandlerInfo) => Promise<Response>
248-
> {
246+
handler(): (
247+
request: Request,
248+
info?: Deno.ServeHandlerInfo,
249+
) => Promise<Response> {
249250
if (this.#buildCache === null) {
250-
this.#buildCache = await ProdBuildCache.fromSnapshot(
251+
this.#buildCache = ProdBuildCache.fromSnapshot(
251252
this.config,
252253
this.#islandRegistry.size,
253254
);

src/app_test.tsx

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Deno.test("FreshApp - .use()", async () => {
1515
})
1616
.get("/", (ctx) => new Response(ctx.state.text));
1717

18-
const server = new FakeServer(await app.handler());
18+
const server = new FakeServer(app.handler());
1919

2020
const res = await server.get("/");
2121
expect(await res.text()).toEqual("AB");
@@ -27,7 +27,7 @@ Deno.test("FreshApp - .use() #2", async () => {
2727
.get("/foo/bar", () => new Response("ok #2"))
2828
.get("/", () => new Response("ok #3"));
2929

30-
const server = new FakeServer(await app.handler());
30+
const server = new FakeServer(app.handler());
3131

3232
const res = await server.get("/");
3333
expect(await res.text()).toEqual("ok #1");
@@ -40,7 +40,7 @@ Deno.test("FreshApp - .get()", async () => {
4040
.get("/", () => new Response("ok"))
4141
.get("/foo", () => new Response("ok"));
4242

43-
const server = new FakeServer(await app.handler());
43+
const server = new FakeServer(app.handler());
4444

4545
let res = await server.get("/");
4646
expect(await res.text()).toEqual("ok");
@@ -54,7 +54,7 @@ Deno.test("FreshApp - .get() with basePath", async () => {
5454
.get("/", () => new Response("ok"))
5555
.get("/foo", () => new Response("ok"));
5656

57-
const server = new FakeServer(await app.handler());
57+
const server = new FakeServer(app.handler());
5858

5959
let res = await server.get("/");
6060
expect(res.status).toEqual(404);
@@ -74,7 +74,7 @@ Deno.test("FreshApp - .post()", async () => {
7474
.post("/", () => new Response("ok"))
7575
.post("/foo", () => new Response("ok"));
7676

77-
const server = new FakeServer(await app.handler());
77+
const server = new FakeServer(app.handler());
7878

7979
let res = await server.post("/");
8080
expect(await res.text()).toEqual("ok");
@@ -88,7 +88,7 @@ Deno.test("FreshApp - .post() with basePath", async () => {
8888
.post("/", () => new Response("ok"))
8989
.post("/foo", () => new Response("ok"));
9090

91-
const server = new FakeServer(await app.handler());
91+
const server = new FakeServer(app.handler());
9292

9393
let res = await server.post("/");
9494
expect(res.status).toEqual(404);
@@ -108,7 +108,7 @@ Deno.test("FreshApp - .patch()", async () => {
108108
.patch("/", () => new Response("ok"))
109109
.patch("/foo", () => new Response("ok"));
110110

111-
const server = new FakeServer(await app.handler());
111+
const server = new FakeServer(app.handler());
112112

113113
let res = await server.patch("/");
114114
expect(await res.text()).toEqual("ok");
@@ -122,7 +122,7 @@ Deno.test("FreshApp - .patch() with basePath", async () => {
122122
.patch("/", () => new Response("ok"))
123123
.patch("/foo", () => new Response("ok"));
124124

125-
const server = new FakeServer(await app.handler());
125+
const server = new FakeServer(app.handler());
126126

127127
let res = await server.patch("/");
128128
expect(res.status).toEqual(404);
@@ -142,7 +142,7 @@ Deno.test("FreshApp - .put()", async () => {
142142
.put("/", () => new Response("ok"))
143143
.put("/foo", () => new Response("ok"));
144144

145-
const server = new FakeServer(await app.handler());
145+
const server = new FakeServer(app.handler());
146146

147147
let res = await server.put("/");
148148
expect(await res.text()).toEqual("ok");
@@ -156,7 +156,7 @@ Deno.test("FreshApp - .put() with basePath", async () => {
156156
.put("/", () => new Response("ok"))
157157
.put("/foo", () => new Response("ok"));
158158

159-
const server = new FakeServer(await app.handler());
159+
const server = new FakeServer(app.handler());
160160

161161
let res = await server.put("/");
162162
expect(res.status).toEqual(404);
@@ -176,7 +176,7 @@ Deno.test("FreshApp - .delete()", async () => {
176176
.delete("/", () => new Response("ok"))
177177
.delete("/foo", () => new Response("ok"));
178178

179-
const server = new FakeServer(await app.handler());
179+
const server = new FakeServer(app.handler());
180180

181181
let res = await server.delete("/");
182182
expect(await res.text()).toEqual("ok");
@@ -190,7 +190,7 @@ Deno.test("FreshApp - .delete() with basePath", async () => {
190190
.delete("/", () => new Response("ok"))
191191
.delete("/foo", () => new Response("ok"));
192192

193-
const server = new FakeServer(await app.handler());
193+
const server = new FakeServer(app.handler());
194194

195195
let res = await server.delete("/");
196196
expect(res.status).toEqual(404);
@@ -208,7 +208,7 @@ Deno.test("FreshApp - wrong method match", async () => {
208208
.get("/", () => new Response("ok"))
209209
.post("/", () => new Response("ok"));
210210

211-
const server = new FakeServer(await app.handler());
211+
const server = new FakeServer(app.handler());
212212

213213
let res = await server.put("/");
214214
expect(res.status).toEqual(405);
@@ -228,7 +228,7 @@ Deno.test("FreshApp - methods with middleware", async () => {
228228
.get("/", (ctx) => new Response(ctx.state.text))
229229
.post("/", (ctx) => new Response(ctx.state.text));
230230

231-
const server = new FakeServer(await app.handler());
231+
const server = new FakeServer(app.handler());
232232

233233
let res = await server.get("/");
234234
expect(await res.text()).toEqual("A");
@@ -250,7 +250,7 @@ Deno.test("FreshApp - .mountApp() compose apps", async () => {
250250
.get("/", () => new Response("ok"))
251251
.mountApp("/foo", innerApp);
252252

253-
const server = new FakeServer(await app.handler());
253+
const server = new FakeServer(app.handler());
254254

255255
let res = await server.get("/");
256256
expect(await res.text()).toEqual("ok");
@@ -275,7 +275,7 @@ Deno.test("FreshApp - .mountApp() self mount, no middleware", async () => {
275275
.get("/", () => new Response("ok"))
276276
.mountApp("/", innerApp);
277277

278-
const server = new FakeServer(await app.handler());
278+
const server = new FakeServer(app.handler());
279279

280280
let res = await server.get("/");
281281
expect(await res.text()).toEqual("ok");
@@ -306,7 +306,7 @@ Deno.test(
306306
.get("/", () => new Response("ok"))
307307
.mountApp("/", innerApp);
308308

309-
const server = new FakeServer(await app.handler());
309+
const server = new FakeServer(app.handler());
310310

311311
let res = await server.get("/");
312312
expect(await res.text()).toEqual("ok");
@@ -338,7 +338,7 @@ Deno.test(
338338
.get("/", () => new Response("ok"))
339339
.mountApp("/", innerApp);
340340

341-
const server = new FakeServer(await app.handler());
341+
const server = new FakeServer(app.handler());
342342

343343
let res = await server.get("/");
344344
expect(await res.text()).toEqual("ok");
@@ -362,7 +362,7 @@ Deno.test("FreshApp - .mountApp() self mount empty", async () => {
362362
const app = new App<{ text: string }>()
363363
.mountApp("/", innerApp);
364364

365-
const server = new FakeServer(await app.handler());
365+
const server = new FakeServer(app.handler());
366366

367367
const res = await server.get("/foo");
368368
expect(await res.text()).toEqual("A");
@@ -385,7 +385,7 @@ Deno.test(
385385
})
386386
.mountApp("/", innerApp);
387387

388-
const server = new FakeServer(await app.handler());
388+
const server = new FakeServer(app.handler());
389389

390390
const res = await server.get("/");
391391
expect(await res.text()).toEqual("Outer_Inner");
@@ -408,7 +408,7 @@ Deno.test("FreshApp - catches errors", async () => {
408408
throw new Error("fail");
409409
});
410410

411-
const server = new FakeServer(await app.handler());
411+
const server = new FakeServer(app.handler());
412412

413413
const res = await server.get("/");
414414
expect(res.status).toEqual(500);
@@ -432,7 +432,7 @@ Deno.test.ignore("FreshApp - finish setup", async () => {
432432
}, getIslandRegistry(app).size),
433433
);
434434

435-
const server = new FakeServer(await app.handler());
435+
const server = new FakeServer(app.handler());
436436
const res = await server.get("/");
437437
const text = await res.text();
438438
expect(text).toContain("Finish setting up");
@@ -462,7 +462,7 @@ Deno.test("FreshApp - sets error on context", async () => {
462462
throw "<mock error>";
463463
});
464464

465-
const server = new FakeServer(await app.handler());
465+
const server = new FakeServer(app.handler());
466466

467467
const res = await server.get("/");
468468
await res.body?.cancel();
@@ -480,7 +480,7 @@ Deno.test("FreshApp - support setting request init in ctx.render()", async () =>
480480
});
481481
});
482482

483-
const server = new FakeServer(await app.handler());
483+
const server = new FakeServer(app.handler());
484484
const res = await server.get("/");
485485
await res.body?.cancel();
486486
expect(res.status).toEqual(416);

src/build_cache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ export interface BuildCache {
2929
}
3030

3131
export class ProdBuildCache implements BuildCache {
32-
static async fromSnapshot(config: ResolvedFreshConfig, islandCount: number) {
32+
static fromSnapshot(config: ResolvedFreshConfig, islandCount: number) {
3333
const snapshotPath = getSnapshotPath(config);
3434

3535
const staticFiles = new Map<string, FileSnapshot>();
3636
const islandToChunk = new Map<string, string>();
3737

3838
let hasSnapshot = false;
3939
try {
40-
const content = await Deno.readTextFile(snapshotPath);
40+
const content = Deno.readTextFileSync(snapshotPath);
4141
const snapshot = JSON.parse(content) as BuildSnapshot;
4242
hasSnapshot = true;
4343
setBuildId(snapshot.buildId);

src/context_test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Deno.test("render asset()", async () => {
3838
</>,
3939
));
4040

41-
const server = new FakeServer(await app.handler());
41+
const server = new FakeServer(app.handler());
4242
const res = await server.get("/");
4343
const doc = parseHtml(await res.text());
4444

@@ -52,7 +52,7 @@ Deno.test("ctx.render - throw with no arguments", async () => {
5252
const app = new App()
5353
// deno-lint-ignore no-explicit-any
5454
.get("/", (ctx) => (ctx as any).render());
55-
const server = new FakeServer(await app.handler());
55+
const server = new FakeServer(app.handler());
5656
const res = await server.get("/");
5757

5858
await res.body?.cancel();
@@ -63,7 +63,7 @@ Deno.test("ctx.render - throw with invalid first arg", async () => {
6363
const app = new App()
6464
// deno-lint-ignore no-explicit-any
6565
.get("/", (ctx) => (ctx as any).render({}));
66-
const server = new FakeServer(await app.handler());
66+
const server = new FakeServer(app.handler());
6767
const res = await server.get("/");
6868

6969
await res.body?.cancel();

src/dev/middlewares/error_overlay/middleware_test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Deno.test("error overlay - show when error is thrown", async () => {
1313
throw new Error("fail");
1414
});
1515

16-
const server = new FakeServer(await app.handler());
16+
const server = new FakeServer(app.handler());
1717
const res = await server.get("/", {
1818
headers: {
1919
accept: "text/html",
@@ -36,7 +36,7 @@ Deno.test("error overlay - should not be visible for HttpError <500", async () =
3636
throw new HttpError(500);
3737
});
3838

39-
const server = new FakeServer(await app.handler());
39+
const server = new FakeServer(app.handler());
4040
let res = await server.get("/", {
4141
headers: {
4242
accept: "text/html",
@@ -74,7 +74,7 @@ Deno.test(
7474
throw new HttpError(404);
7575
});
7676

77-
const server = new FakeServer(await app.handler());
77+
const server = new FakeServer(app.handler());
7878
const res = await server.get("/", {
7979
headers: {
8080
accept: "text/html",
@@ -94,7 +94,7 @@ Deno.test("error overlay - should not be visible in prod", async () => {
9494
throw new HttpError(500);
9595
});
9696

97-
const server = new FakeServer(await app.handler());
97+
const server = new FakeServer(app.handler());
9898
const res = await server.get("/", {
9999
headers: {
100100
accept: "text/html",

src/error.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { STATUS_TEXT } from "@std/http/status";
1717
* throw new HttpError(404, "Nothing here");
1818
* });
1919
*
20-
* const handler = await app.handler();
20+
* const handler = app.handler();
2121
*
2222
* try {
2323
* await handler(new Request("http://localhost/not-found"))
@@ -43,7 +43,7 @@ export class HttpError extends Error {
4343
* throw new HttpError(404, "Nothing here");
4444
* });
4545
*
46-
* const handler = await app.handler();
46+
* const handler = app.handler();
4747
*
4848
* try {
4949
* await handler(new Request("http://localhost/not-found"))

src/plugins/fs_routes/mod_test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async function createServer<T>(
3535
_fs: createFakeFs(files),
3636
} as FsRoutesOptions & TESTING_ONLY__FsRoutesOptions,
3737
);
38-
return new FakeServer(await app.handler());
38+
return new FakeServer(app.handler());
3939
}
4040

4141
Deno.test("fsRoutes - throws error when file has no exports", async () => {

tests/active_links_test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Deno.test({
6666
return ctx.render(<View />);
6767
});
6868

69-
const server = new FakeServer(await app.handler());
69+
const server = new FakeServer(app.handler());
7070
let res = await server.get("/active_nav");
7171
let doc = parseHtml(await res.text());
7272

tests/fixture_precompile/valid/main.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const app = new App({ staticDir: "./static" }).get(
2525
),
2626
);
2727

28-
const handler = await app.handler();
28+
const handler = app.handler();
2929
const res = await handler(new Request("http://localhost/"));
3030
// deno-lint-ignore no-console
3131
console.log(await res.text());

tests/islands_test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ Deno.test({
718718
</Doc>,
719719
));
720720

721-
const server = new FakeServer(await app.handler());
721+
const server = new FakeServer(app.handler());
722722
const res = await server.get("/");
723723
await res.body?.cancel();
724724

0 commit comments

Comments
 (0)