diff --git a/CHANGES.md b/CHANGES.md index 78565f211..effc6c070 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,11 +10,12 @@ To be released. ### @fedify/init - - Fixed the Nitro and Next.js project templates so their generated - *logging.ts* files are loaded during server startup. Nitro projects now - get a server plugin that imports the LogTape configuration, and Next.js - projects get an *instrumentation.ts* `register()` hook that imports it in - the Node.js runtime before Fedify handles requests. [[#725], [#727]] + - Fixed the Astro, Nitro, and Next.js project templates so their generated + *logging.ts* files are loaded during server startup before Fedify handles + requests. Nitro projects now get a server plugin that imports the LogTape + configuration, Next.js projects get an *instrumentation.ts* `register()` + hook that imports it in the Node.js runtime, and Astro projects import it + in *src/middleware.ts*. [[#725], [#727]] [#725]: https://github.com/fedify-dev/fedify/issues/725 [#727]: https://github.com/fedify-dev/fedify/pull/727 diff --git a/packages/init/src/templates/astro/src/middleware.ts.tpl b/packages/init/src/templates/astro/src/middleware.ts.tpl index 044e4eaa9..5a5d9105c 100644 --- a/packages/init/src/templates/astro/src/middleware.ts.tpl +++ b/packages/init/src/templates/astro/src/middleware.ts.tpl @@ -1,3 +1,4 @@ +import "./logging.ts"; import { fedifyMiddleware } from "@fedify/astro"; import federation from "./federation.ts"; diff --git a/packages/init/src/webframeworks.test.ts b/packages/init/src/webframeworks.test.ts index 21c81906f..3e90ec814 100644 --- a/packages/init/src/webframeworks.test.ts +++ b/packages/init/src/webframeworks.test.ts @@ -1,5 +1,6 @@ import { ok } from "node:assert/strict"; import test from "node:test"; +import astroDescription from "./webframeworks/astro.ts"; import nextDescription from "./webframeworks/next.ts"; import nitroDescription from "./webframeworks/nitro.ts"; @@ -44,3 +45,22 @@ test("Next.js template loads LogTape through instrumentation", async () => { ok(instrumentation.includes("process.env.NEXT_RUNTIME")); ok(instrumentation.includes('await import("./logging")')); }); + +test("Astro template loads LogTape through middleware", async () => { + const { files } = await astroDescription.init({ + projectName: "test-app", + dir: ".", + command: "init", + packageManager: "npm", + kvStore: "in-memory", + messageQueue: "in-process", + webFramework: "astro", + testMode: false, + dryRun: true, + }); + + ok(files); + const middleware = files["src/middleware.ts"]; + ok(middleware); + ok(middleware.includes('import "./logging.ts";')); +});