From 96414accc447d04ee13dc218cdf996ef4f8ca751 Mon Sep 17 00:00:00 2001 From: Hong Minhee Date: Mon, 27 Apr 2026 00:33:24 +0900 Subject: [PATCH 1/2] Load Astro logging in init templates Import the generated LogTape setup from Astro middleware so scaffolded Astro applications configure logging before Fedify handles requests. Add regression coverage for the generated Astro middleware and update the changelog entry for the broader init template fix. Fixes https://github.com/fedify-dev/fedify/issues/725 Assisted-by: Codex:gpt-5.5 --- CHANGES.md | 7 ++++--- .../src/templates/astro/src/middleware.ts.tpl | 1 + packages/init/src/webframeworks.test.ts | 20 +++++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 78565f211..33bc1f2f0 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 + - Fixed the Astro, 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 + 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 before Fedify handles requests. [[#725], [#727]] + the Node.js runtime, and Astro projects import it from *src/middleware.ts* + before Fedify handles requests. [[#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";')); +}); From 2b8b3200c815c06f0b8c0cc114563c2fcec70288 Mon Sep 17 00:00:00 2001 From: Hong Minhee Date: Mon, 27 Apr 2026 00:54:28 +0900 Subject: [PATCH 2/2] Clarify init logging changelog Tighten the changelog wording for the init template logging fix so the startup timing applies to Astro, Nitro, and Next.js, and so the Astro middleware is described as the place where the logging setup is imported. Review comment: https://github.com/fedify-dev/fedify/pull/729#discussion_r3143723678 Assisted-by: Codex:gpt-5.5 --- CHANGES.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 33bc1f2f0..effc6c070 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,11 +11,11 @@ To be released. ### @fedify/init - Fixed the Astro, 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, Next.js - projects get an *instrumentation.ts* `register()` hook that imports it in - the Node.js runtime, and Astro projects import it from *src/middleware.ts* - before Fedify handles requests. [[#725], [#727]] + *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