@stratify/cli 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -4,8 +4,6 @@ import { createAdapter } from "@stratify/core";
|
|
|
4
4
|
* Exposes Fastify version for the current instance context.
|
|
5
5
|
*/
|
|
6
6
|
export const versionAdapter = createAdapter({
|
|
7
|
-
name: "version",
|
|
8
|
-
expose: ({ fastify }) =>
|
|
9
|
-
version: fastify.version
|
|
10
|
-
})
|
|
7
|
+
name: "version", // optional, used by tree printer
|
|
8
|
+
expose: ({ fastify }) => fastify.version
|
|
11
9
|
});
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { createHooks } from "@stratify/core";
|
|
2
|
+
import { versionAdapter } from "../adapters/version.adapter";
|
|
2
3
|
|
|
3
4
|
export const httpHooks = createHooks({
|
|
4
5
|
type: "http",
|
|
5
|
-
name: "http-core",
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
name: "http-core",
|
|
7
|
+
adaps: { version: versionAdapter },
|
|
8
|
+
build: async ({ builder, adaps }) => {
|
|
9
|
+
// Adds headers to every request
|
|
10
|
+
builder.addHook("onSend", async (_req, reply, payload) => {
|
|
11
|
+
reply.header("x-fastify-version", adaps.version);
|
|
12
|
+
return payload;
|
|
10
13
|
});
|
|
11
|
-
|
|
12
|
-
}
|
|
14
|
+
},
|
|
13
15
|
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { describe, test } from "node:test";
|
|
2
|
+
import assert from "node:assert";
|
|
3
|
+
import { createApp } from "@stratify/core";
|
|
4
|
+
import { tasksModule } from "../src/tasks/tasks.module.js";
|
|
5
|
+
|
|
6
|
+
describe("http hooks", () => {
|
|
7
|
+
test("sets x-fastify-version header on all responses", async () => {
|
|
8
|
+
const app = await createApp({ root: tasksModule });
|
|
9
|
+
|
|
10
|
+
const res = await app.inject({ method: "GET", url: "/tasks" });
|
|
11
|
+
assert.strictEqual(res.statusCode, 200);
|
|
12
|
+
|
|
13
|
+
const versionHeader = res.headers["x-fastify-version"];
|
|
14
|
+
assert.ok(versionHeader, "x-fastify-version header should be set");
|
|
15
|
+
|
|
16
|
+
assert.strictEqual(versionHeader, app.version);
|
|
17
|
+
|
|
18
|
+
await app.close();
|
|
19
|
+
});
|
|
20
|
+
});
|