Skip to content

Commit 547b13f

Browse files
authored
Merge branch 'master' into make-v26
2 parents fc3d302 + 4ef8bae commit 547b13f

10 files changed

Lines changed: 30 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727

2828
## Version 25
2929

30+
### v25.6.0
31+
32+
- Added `afterRouting` hook to server configuration:
33+
- Similar to `beforeRouting` one;
34+
- A code to execute after processing the Routing of your API, but before error handling.
35+
3036
### v25.5.3
3137

3238
- Updated environment requirements in the Readme:

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"build": "pnpm build:docs && pnpm build:client",
99
"build:docs": "tsx generate-documentation.ts",
1010
"build:client": "tsx generate-client.ts",
11-
"pretest": "tsc --noEmit",
11+
"pretest": "tsc",
1212
"test": "vitest run index.spec.ts"
1313
},
1414
"devDependencies": {

express-zod-api/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "express-zod-api",
3-
"version": "25.5.3",
3+
"version": "25.6.0",
44
"description": "A Typescript framework to help you get an API server up and running with I/O schema validation and custom middlewares in minutes.",
55
"license": "MIT",
66
"repository": {
@@ -17,7 +17,7 @@
1717
"funding": "https://github.com/sponsors/RobinTail",
1818
"scripts": {
1919
"build": "tsdown",
20-
"pretest": "tsc --noEmit",
20+
"pretest": "tsc",
2121
"test": "vitest run --coverage",
2222
"bench": "vitest bench --run ./bench",
2323
"prepublishOnly": "eslint && pnpm -r build && pnpm test",

express-zod-api/src/config-type.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ interface GracefulOptions {
135135
beforeExit?: () => void | Promise<void>;
136136
}
137137

138-
type BeforeRouting = (params: {
138+
type ServerHook = (params: {
139139
app: IRouter;
140140
/** @desc Returns child logger for the given request (if configured) or the configured logger otherwise */
141141
getLogger: GetLogger;
@@ -199,7 +199,12 @@ export interface ServerConfig extends CommonConfig {
199199
* @desc It can help to avoid making a DIY solution based on the attachRouting() approach.
200200
* @example ({ app }) => { app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument)); }
201201
* */
202-
beforeRouting?: BeforeRouting;
202+
beforeRouting?: ServerHook;
203+
/**
204+
* @desc A code to execute after processing the Routing of your API, but before error handling.
205+
* @see beforeRouting
206+
* */
207+
afterRouting?: ServerHook;
203208
/**
204209
* @desc Rejects new connections and attempts to finish ongoing ones in the specified time before exit.
205210
* */

express-zod-api/src/server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ export const createServer = async (config: ServerConfig, routing: Routing) => {
8989
: [],
9090
};
9191
initRouting({ app, routing, getLogger, config, parsers });
92+
93+
await config.afterRouting?.({ app, getLogger });
9294
app.use(catcher, notFoundHandler);
9395

9496
const created: Array<http.Server | https.Server> = [];

express-zod-api/tests/server.spec.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ describe("Server", () => {
9090
expect(httpListenSpy).toHaveBeenCalledWith(port, expect.any(Function));
9191
});
9292

93-
test("Should create server with custom parsers, logger, error handler and beforeRouting", async () => {
93+
test("Should create server with custom parsers, logger, error handler and hooks", async () => {
9494
const customLogger = new BuiltinLogger({ level: "silent" });
9595
const infoMethod = vi.spyOn(customLogger, "info");
9696
const port = givePort();
@@ -101,6 +101,7 @@ describe("Server", () => {
101101
rawParser: vi.fn(),
102102
formParser: vi.fn(),
103103
beforeRouting: vi.fn(),
104+
afterRouting: vi.fn(),
104105
cors: true,
105106
startupLogo: false,
106107
errorHandler: {
@@ -147,10 +148,12 @@ describe("Server", () => {
147148
);
148149
expect(appMock.use).toHaveBeenCalledTimes(2);
149150
expect(configMock.errorHandler.handler).toHaveBeenCalledTimes(0);
150-
expect(configMock.beforeRouting).toHaveBeenCalledWith({
151-
app: appMock,
152-
getLogger: expect.any(Function),
153-
});
151+
for (const hook of ["beforeRouting", "afterRouting"] as const) {
152+
expect(configMock[hook]).toHaveBeenCalledWith({
153+
app: appMock,
154+
getLogger: expect.any(Function),
155+
});
156+
}
154157
expect(infoMethod).toHaveBeenCalledTimes(1);
155158
expect(infoMethod).toHaveBeenCalledWith(`Listening`, { port });
156159
expect(appMock.get).toHaveBeenCalledTimes(1);

issue952-test/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"extends": "../tsconfig.json",
33
"compilerOptions": {
44
"declaration": true,
5+
"noEmit": false,
56
"emitDeclarationOnly": true
67
}
78
}

migration/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"bugs": "https://github.com/RobinTail/express-zod-api/issues",
1616
"funding": "https://github.com/sponsors/RobinTail",
1717
"scripts": {
18-
"pretest": "tsc --noEmit",
18+
"pretest": "tsc",
1919
"test": "vitest run --globals",
2020
"build": "tsdown",
2121
"prepublishOnly": "eslint && pnpm test && pnpm build"

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"compilerOptions": {
44
"module": "node20",
55
"target": "es2023",
6+
"noEmit": true,
67
"allowImportingTsExtensions": true,
78
"noImplicitAny": true,
89
"noImplicitOverride": true,

zod-plugin/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"bugs": "https://github.com/RobinTail/express-zod-api/issues",
1717
"funding": "https://github.com/sponsors/RobinTail",
1818
"scripts": {
19-
"pretest": "tsc --noEmit",
19+
"pretest": "tsc",
2020
"test": "vitest run",
2121
"build": "tsdown",
2222
"prepublishOnly": "eslint && pnpm test && pnpm build"

0 commit comments

Comments
 (0)