diff --git a/src/app.ts b/src/app.ts index 01fdab20..fb51e761 100644 --- a/src/app.ts +++ b/src/app.ts @@ -243,11 +243,12 @@ export class App { return this; } - async handler(): Promise< - (request: Request, info?: Deno.ServeHandlerInfo) => Promise - > { + handler(): ( + request: Request, + info?: Deno.ServeHandlerInfo, + ) => Promise { if (this.#buildCache === null) { - this.#buildCache = await ProdBuildCache.fromSnapshot( + this.#buildCache = ProdBuildCache.fromSnapshot( this.config, this.#islandRegistry.size, ); diff --git a/src/app_test.tsx b/src/app_test.tsx index d193006d..22d61cab 100644 --- a/src/app_test.tsx +++ b/src/app_test.tsx @@ -15,7 +15,7 @@ Deno.test("FreshApp - .use()", async () => { }) .get("/", (ctx) => new Response(ctx.state.text)); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); const res = await server.get("/"); expect(await res.text()).toEqual("AB"); @@ -27,7 +27,7 @@ Deno.test("FreshApp - .use() #2", async () => { .get("/foo/bar", () => new Response("ok #2")) .get("/", () => new Response("ok #3")); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); const res = await server.get("/"); expect(await res.text()).toEqual("ok #1"); @@ -40,7 +40,7 @@ Deno.test("FreshApp - .get()", async () => { .get("/", () => new Response("ok")) .get("/foo", () => new Response("ok")); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); let res = await server.get("/"); expect(await res.text()).toEqual("ok"); @@ -54,7 +54,7 @@ Deno.test("FreshApp - .get() with basePath", async () => { .get("/", () => new Response("ok")) .get("/foo", () => new Response("ok")); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); let res = await server.get("/"); expect(res.status).toEqual(404); @@ -74,7 +74,7 @@ Deno.test("FreshApp - .post()", async () => { .post("/", () => new Response("ok")) .post("/foo", () => new Response("ok")); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); let res = await server.post("/"); expect(await res.text()).toEqual("ok"); @@ -88,7 +88,7 @@ Deno.test("FreshApp - .post() with basePath", async () => { .post("/", () => new Response("ok")) .post("/foo", () => new Response("ok")); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); let res = await server.post("/"); expect(res.status).toEqual(404); @@ -108,7 +108,7 @@ Deno.test("FreshApp - .patch()", async () => { .patch("/", () => new Response("ok")) .patch("/foo", () => new Response("ok")); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); let res = await server.patch("/"); expect(await res.text()).toEqual("ok"); @@ -122,7 +122,7 @@ Deno.test("FreshApp - .patch() with basePath", async () => { .patch("/", () => new Response("ok")) .patch("/foo", () => new Response("ok")); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); let res = await server.patch("/"); expect(res.status).toEqual(404); @@ -142,7 +142,7 @@ Deno.test("FreshApp - .put()", async () => { .put("/", () => new Response("ok")) .put("/foo", () => new Response("ok")); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); let res = await server.put("/"); expect(await res.text()).toEqual("ok"); @@ -156,7 +156,7 @@ Deno.test("FreshApp - .put() with basePath", async () => { .put("/", () => new Response("ok")) .put("/foo", () => new Response("ok")); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); let res = await server.put("/"); expect(res.status).toEqual(404); @@ -176,7 +176,7 @@ Deno.test("FreshApp - .delete()", async () => { .delete("/", () => new Response("ok")) .delete("/foo", () => new Response("ok")); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); let res = await server.delete("/"); expect(await res.text()).toEqual("ok"); @@ -190,7 +190,7 @@ Deno.test("FreshApp - .delete() with basePath", async () => { .delete("/", () => new Response("ok")) .delete("/foo", () => new Response("ok")); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); let res = await server.delete("/"); expect(res.status).toEqual(404); @@ -208,7 +208,7 @@ Deno.test("FreshApp - wrong method match", async () => { .get("/", () => new Response("ok")) .post("/", () => new Response("ok")); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); let res = await server.put("/"); expect(res.status).toEqual(405); @@ -228,7 +228,7 @@ Deno.test("FreshApp - methods with middleware", async () => { .get("/", (ctx) => new Response(ctx.state.text)) .post("/", (ctx) => new Response(ctx.state.text)); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); let res = await server.get("/"); expect(await res.text()).toEqual("A"); @@ -250,7 +250,7 @@ Deno.test("FreshApp - .mountApp() compose apps", async () => { .get("/", () => new Response("ok")) .mountApp("/foo", innerApp); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); let res = await server.get("/"); expect(await res.text()).toEqual("ok"); @@ -275,7 +275,7 @@ Deno.test("FreshApp - .mountApp() self mount, no middleware", async () => { .get("/", () => new Response("ok")) .mountApp("/", innerApp); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); let res = await server.get("/"); expect(await res.text()).toEqual("ok"); @@ -306,7 +306,7 @@ Deno.test( .get("/", () => new Response("ok")) .mountApp("/", innerApp); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); let res = await server.get("/"); expect(await res.text()).toEqual("ok"); @@ -338,7 +338,7 @@ Deno.test( .get("/", () => new Response("ok")) .mountApp("/", innerApp); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); let res = await server.get("/"); expect(await res.text()).toEqual("ok"); @@ -362,7 +362,7 @@ Deno.test("FreshApp - .mountApp() self mount empty", async () => { const app = new App<{ text: string }>() .mountApp("/", innerApp); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); const res = await server.get("/foo"); expect(await res.text()).toEqual("A"); @@ -385,7 +385,7 @@ Deno.test( }) .mountApp("/", innerApp); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); const res = await server.get("/"); expect(await res.text()).toEqual("Outer_Inner"); @@ -408,7 +408,7 @@ Deno.test("FreshApp - catches errors", async () => { throw new Error("fail"); }); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); const res = await server.get("/"); expect(res.status).toEqual(500); @@ -432,7 +432,7 @@ Deno.test.ignore("FreshApp - finish setup", async () => { }, getIslandRegistry(app).size), ); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); const res = await server.get("/"); const text = await res.text(); expect(text).toContain("Finish setting up"); @@ -462,7 +462,7 @@ Deno.test("FreshApp - sets error on context", async () => { throw ""; }); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); const res = await server.get("/"); await res.body?.cancel(); @@ -480,7 +480,7 @@ Deno.test("FreshApp - support setting request init in ctx.render()", async () => }); }); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); const res = await server.get("/"); await res.body?.cancel(); expect(res.status).toEqual(416); diff --git a/src/build_cache.ts b/src/build_cache.ts index ccc06758..ada90e00 100644 --- a/src/build_cache.ts +++ b/src/build_cache.ts @@ -29,7 +29,7 @@ export interface BuildCache { } export class ProdBuildCache implements BuildCache { - static async fromSnapshot(config: ResolvedFreshConfig, islandCount: number) { + static fromSnapshot(config: ResolvedFreshConfig, islandCount: number) { const snapshotPath = getSnapshotPath(config); const staticFiles = new Map(); @@ -37,7 +37,7 @@ export class ProdBuildCache implements BuildCache { let hasSnapshot = false; try { - const content = await Deno.readTextFile(snapshotPath); + const content = Deno.readTextFileSync(snapshotPath); const snapshot = JSON.parse(content) as BuildSnapshot; hasSnapshot = true; setBuildId(snapshot.buildId); diff --git a/src/context_test.tsx b/src/context_test.tsx index ea26bfb2..692ce01f 100644 --- a/src/context_test.tsx +++ b/src/context_test.tsx @@ -38,7 +38,7 @@ Deno.test("render asset()", async () => { , )); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); const res = await server.get("/"); const doc = parseHtml(await res.text()); @@ -52,7 +52,7 @@ Deno.test("ctx.render - throw with no arguments", async () => { const app = new App() // deno-lint-ignore no-explicit-any .get("/", (ctx) => (ctx as any).render()); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); const res = await server.get("/"); await res.body?.cancel(); @@ -63,7 +63,7 @@ Deno.test("ctx.render - throw with invalid first arg", async () => { const app = new App() // deno-lint-ignore no-explicit-any .get("/", (ctx) => (ctx as any).render({})); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); const res = await server.get("/"); await res.body?.cancel(); diff --git a/src/dev/middlewares/error_overlay/middleware_test.tsx b/src/dev/middlewares/error_overlay/middleware_test.tsx index 1f925231..ba72b8c3 100644 --- a/src/dev/middlewares/error_overlay/middleware_test.tsx +++ b/src/dev/middlewares/error_overlay/middleware_test.tsx @@ -13,7 +13,7 @@ Deno.test("error overlay - show when error is thrown", async () => { throw new Error("fail"); }); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); const res = await server.get("/", { headers: { accept: "text/html", @@ -36,7 +36,7 @@ Deno.test("error overlay - should not be visible for HttpError <500", async () = throw new HttpError(500); }); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); let res = await server.get("/", { headers: { accept: "text/html", @@ -74,7 +74,7 @@ Deno.test( throw new HttpError(404); }); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); const res = await server.get("/", { headers: { accept: "text/html", @@ -94,7 +94,7 @@ Deno.test("error overlay - should not be visible in prod", async () => { throw new HttpError(500); }); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); const res = await server.get("/", { headers: { accept: "text/html", diff --git a/src/error.ts b/src/error.ts index d2cbaa71..610b09ba 100644 --- a/src/error.ts +++ b/src/error.ts @@ -17,7 +17,7 @@ import { STATUS_TEXT } from "@std/http/status"; * throw new HttpError(404, "Nothing here"); * }); * - * const handler = await app.handler(); + * const handler = app.handler(); * * try { * await handler(new Request("http://localhost/not-found")) @@ -43,7 +43,7 @@ export class HttpError extends Error { * throw new HttpError(404, "Nothing here"); * }); * - * const handler = await app.handler(); + * const handler = app.handler(); * * try { * await handler(new Request("http://localhost/not-found")) diff --git a/src/plugins/fs_routes/mod_test.tsx b/src/plugins/fs_routes/mod_test.tsx index 1f36890d..990b42f1 100644 --- a/src/plugins/fs_routes/mod_test.tsx +++ b/src/plugins/fs_routes/mod_test.tsx @@ -35,7 +35,7 @@ async function createServer( _fs: createFakeFs(files), } as FsRoutesOptions & TESTING_ONLY__FsRoutesOptions, ); - return new FakeServer(await app.handler()); + return new FakeServer(app.handler()); } Deno.test("fsRoutes - throws error when file has no exports", async () => { diff --git a/tests/active_links_test.tsx b/tests/active_links_test.tsx index a2c597f0..b522aed0 100644 --- a/tests/active_links_test.tsx +++ b/tests/active_links_test.tsx @@ -66,7 +66,7 @@ Deno.test({ return ctx.render(); }); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); let res = await server.get("/active_nav"); let doc = parseHtml(await res.text()); diff --git a/tests/fixture_precompile/valid/main.tsx b/tests/fixture_precompile/valid/main.tsx index 35ec2605..7beef069 100644 --- a/tests/fixture_precompile/valid/main.tsx +++ b/tests/fixture_precompile/valid/main.tsx @@ -25,7 +25,7 @@ const app = new App({ staticDir: "./static" }).get( ), ); -const handler = await app.handler(); +const handler = app.handler(); const res = await handler(new Request("http://localhost/")); // deno-lint-ignore no-console console.log(await res.text()); diff --git a/tests/islands_test.tsx b/tests/islands_test.tsx index 294770cf..f1022f4f 100644 --- a/tests/islands_test.tsx +++ b/tests/islands_test.tsx @@ -718,7 +718,7 @@ Deno.test({ , )); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); const res = await server.get("/"); await res.body?.cancel(); diff --git a/tests/partials_test.tsx b/tests/partials_test.tsx index 9c4ba876..ae6815af 100644 --- a/tests/partials_test.tsx +++ b/tests/partials_test.tsx @@ -188,7 +188,7 @@ Deno.test({ ); }); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); let checked = false; try { const res = await server.get("/"); @@ -306,7 +306,7 @@ Deno.test({ }); await buildProd(app); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); let checked = false; try { const res = await server.get("/"); @@ -845,7 +845,7 @@ Deno.test({ ); }); - const server = new FakeServer(await app.handler()); + const server = new FakeServer(app.handler()); const res = await server.get("/"); const html = await res.text(); diff --git a/tests/test_utils.tsx b/tests/test_utils.tsx index fd0a4052..407eb6f6 100644 --- a/tests/test_utils.tsx +++ b/tests/test_utils.tsx @@ -83,7 +83,7 @@ export async function withBrowserApp( hostname: "localhost", port: 0, signal: aborter.signal, - }, await app.handler()); + }, app.handler()); const browser = await launch({ args: [ diff --git a/www/main_test.ts b/www/main_test.ts index 6ed62596..87ad4d1b 100644 --- a/www/main_test.ts +++ b/www/main_test.ts @@ -5,7 +5,7 @@ import { expect } from "@std/expect"; import { retry } from "@std/async/retry"; await buildProd(app); -const handler = await app.handler(); +const handler = app.handler(); Deno.test("CORS should not set on GET /fresh-badge.svg", async () => { const req = new Request("http://localhost/fresh-badge.svg");