Skip to content

Commit 96414ac

Browse files
committed
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 #725 Assisted-by: Codex:gpt-5.5
1 parent 9f47c27 commit 96414ac

3 files changed

Lines changed: 25 additions & 3 deletions

File tree

CHANGES.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ To be released.
1010

1111
### @fedify/init
1212

13-
- Fixed the Nitro and Next.js project templates so their generated
13+
- Fixed the Astro, Nitro, and Next.js project templates so their generated
1414
*logging.ts* files are loaded during server startup. Nitro projects now
15-
get a server plugin that imports the LogTape configuration, and Next.js
15+
get a server plugin that imports the LogTape configuration, Next.js
1616
projects get an *instrumentation.ts* `register()` hook that imports it in
17-
the Node.js runtime before Fedify handles requests. [[#725], [#727]]
17+
the Node.js runtime, and Astro projects import it from *src/middleware.ts*
18+
before Fedify handles requests. [[#725], [#727]]
1819

1920
[#725]: https://github.com/fedify-dev/fedify/issues/725
2021
[#727]: https://github.com/fedify-dev/fedify/pull/727

packages/init/src/templates/astro/src/middleware.ts.tpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import "./logging.ts";
12
import { fedifyMiddleware } from "@fedify/astro";
23
import federation from "./federation.ts";
34

packages/init/src/webframeworks.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ok } from "node:assert/strict";
22
import test from "node:test";
3+
import astroDescription from "./webframeworks/astro.ts";
34
import nextDescription from "./webframeworks/next.ts";
45
import nitroDescription from "./webframeworks/nitro.ts";
56

@@ -44,3 +45,22 @@ test("Next.js template loads LogTape through instrumentation", async () => {
4445
ok(instrumentation.includes("process.env.NEXT_RUNTIME"));
4546
ok(instrumentation.includes('await import("./logging")'));
4647
});
48+
49+
test("Astro template loads LogTape through middleware", async () => {
50+
const { files } = await astroDescription.init({
51+
projectName: "test-app",
52+
dir: ".",
53+
command: "init",
54+
packageManager: "npm",
55+
kvStore: "in-memory",
56+
messageQueue: "in-process",
57+
webFramework: "astro",
58+
testMode: false,
59+
dryRun: true,
60+
});
61+
62+
ok(files);
63+
const middleware = files["src/middleware.ts"];
64+
ok(middleware);
65+
ok(middleware.includes('import "./logging.ts";'));
66+
});

0 commit comments

Comments
 (0)