@art-ws/fastify-http-server 2.0.15 → 2.0.17

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.
@@ -4,7 +4,7 @@ export type { FastifyInstance, FastifyReply, FastifyRequest, FastifyRouteShortha
4
4
  export type FastifyHook = (options: {
5
5
  fastify: FastifyInstance;
6
6
  }) => Promise<void>;
7
- export declare function createHttpServer({ routes, port, handlers, plugins, onWebsocket, onPlugin, onBeforeReady, onAfterReady, }: {
7
+ export declare function createHttpServer({ routes, port, handlers, plugins, onWebsocket, onPlugin, onBeforeReady, onAfterReady, onAfterListen, }: {
8
8
  routes: RouteDef<FastifyRequest, FastifyReply, FastifyInstance>[];
9
9
  port?: number;
10
10
  handlers?: {
@@ -24,6 +24,7 @@ export declare function createHttpServer({ routes, port, handlers, plugins, onWe
24
24
  onPlugin?: FastifyHook;
25
25
  onBeforeReady?: FastifyHook;
26
26
  onAfterReady?: FastifyHook;
27
+ onAfterListen?: FastifyHook;
27
28
  }): Promise<{
28
29
  port: number;
29
30
  fastify: Fastify.FastifyInstance<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, Fastify.FastifyBaseLogger, Fastify.FastifyTypeProviderDefault> & PromiseLike<Fastify.FastifyInstance<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, Fastify.FastifyBaseLogger, Fastify.FastifyTypeProviderDefault>> & {
@@ -6,7 +6,7 @@ import formbody from "@fastify/formbody";
6
6
  import multipart from "@fastify/multipart";
7
7
  import fastifyStatic from "@fastify/static";
8
8
  import Fastify, {} from "fastify";
9
- export async function createHttpServer({ routes, port, handlers, plugins, onWebsocket, onPlugin, onBeforeReady, onAfterReady, }) {
9
+ export async function createHttpServer({ routes, port, handlers, plugins, onWebsocket, onPlugin, onBeforeReady, onAfterReady, onAfterListen, }) {
10
10
  const fastify = Fastify({
11
11
  // https://fastify.dev/docs/latest/Reference/Server/#exposeheadroutes
12
12
  exposeHeadRoutes: true,
@@ -87,14 +87,17 @@ export async function createHttpServer({ routes, port, handlers, plugins, onWebs
87
87
  }
88
88
  fastify[method](path, { ...(options || {}) }, fastifyHandler);
89
89
  });
90
- onBeforeReady?.({ fastify });
91
- await fastify.ready();
92
- onAfterReady?.({ fastify });
90
+ if (onBeforeReady || onAfterReady) {
91
+ onBeforeReady?.({ fastify });
92
+ await fastify.ready();
93
+ onAfterReady?.({ fastify });
94
+ }
93
95
  if (port) {
94
96
  try {
95
97
  const host = "0.0.0.0";
96
98
  await fastify.listen({ port, host });
97
99
  console.log(`Listening on http://${host}:${port} ...`);
100
+ onAfterListen?.({ fastify });
98
101
  }
99
102
  catch (err) {
100
103
  fastify.log.error(err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@art-ws/fastify-http-server",
3
- "version": "2.0.15",
3
+ "version": "2.0.17",
4
4
  "description": "Fastify Http server",
5
5
  "license": "UNLICENSED",
6
6
  "author": "Alexander Shagin",
@@ -17,15 +17,15 @@
17
17
  "@fastify/static": "^8.2.0",
18
18
  "@fastify/websocket": "^11.2.0",
19
19
  "fastify": "^5.5.0",
20
- "@art-ws/http-server": "2.0.12",
21
- "@art-ws/di": "2.0.20"
20
+ "@art-ws/http-server": "2.0.14",
21
+ "@art-ws/di": "2.0.21"
22
22
  },
23
23
  "devDependencies": {
24
24
  "eslint": "^9.34.0",
25
25
  "typescript": "^5.9.2",
26
26
  "vitest": "^3.2.4",
27
- "@art-ws/config-eslint": "2.0.3",
28
- "@art-ws/config-ts": "2.0.6"
27
+ "@art-ws/config-ts": "2.0.6",
28
+ "@art-ws/config-eslint": "2.0.3"
29
29
  },
30
30
  "scripts": {
31
31
  "build": "tsc",