Skip to content

Commit

Permalink
feat(fastify): added additional options as 'server' and now server ca…
Browse files Browse the repository at this point in the history
…n be started from the module itself
  • Loading branch information
Stradivario committed Apr 3, 2024
1 parent 81da725 commit 8188adf
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"author": "Kristiyan Tachev",
"license": "MIT",
"devDependencies": {
"@rhtml/di": "^0.0.128",
"@rhtml/di": "^0.0.132",
"@rxdi/bolt": "^0.24.3",
"@types/jest": "^24.0.18",
"@types/node": "^20.11.24",
Expand Down Expand Up @@ -62,4 +62,4 @@
"fastify": "^4.26.2",
"mongoose": "^8.2.1"
}
}
}
4 changes: 2 additions & 2 deletions packages/fastify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@types/jest": "^24.0.18",
"jest": "^24.9.0",
"ts-jest": "25.2.1",
"@rhtml/di": "^0.0.128",
"@rhtml/di": "^0.0.132",
"typescript": "^5.3.3"
},
"author": "Kristiyan Tachev",
Expand All @@ -40,4 +40,4 @@
"types": "./dist/index.d.ts",
"module": "./dist/index.js",
"typings": "./dist/index.d.ts"
}
}
10 changes: 9 additions & 1 deletion packages/fastify/src/fastify.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Module, ModuleWithProviders } from '@rhtml/di';
import fastify, { FastifyInstance } from 'fastify';

import { Fastify, FastifyModuleOptions } from './fastify.tokens';
import { Fastify, FastifyListen, FastifyModuleOptions } from './fastify.tokens';
import { addSchema, corsHook, globalErrorHandler, pipe } from './helpers';

@Module()
Expand Down Expand Up @@ -31,6 +31,14 @@ export class FastifyModule {
)(instance);
},
},

{
provide: FastifyListen,
deps: [Fastify],
provideAtEnd: true,
useFactory: (instance: FastifyInstance) =>
instance.listen(options.server),
},
],
};
}
Expand Down
3 changes: 3 additions & 0 deletions packages/fastify/src/fastify.tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
FastifyError,
FastifyHttpOptions,
FastifyInstance,
FastifyListenOptions,
FastifyPluginCallback,
FastifyRegisterOptions,
FastifyReply,
Expand All @@ -13,6 +14,7 @@ import {
import { CorsOptions } from './helpers/hooks/cors.hook';

export const Fastify = new InjectionToken<FastifyInstance>();
export const FastifyListen = new InjectionToken<string>();

export interface FastifyPlugin {
module: FastifyPluginCallback;
Expand All @@ -32,4 +34,5 @@ export interface FastifyModuleOptions extends FastifyHttpOptions<never> {
schemas: FastifySchema[];
globalErrorHandler: GlobalErrorHandler;
cors: CorsOptions;
server: FastifyListenOptions;
}
6 changes: 3 additions & 3 deletions packages/mongoose/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"@types/jest": "^24.0.18",
"jest": "^24.9.0",
"ts-jest": "25.2.1",
"@rhtml/di": "^0.0.128",
"typescript": "^5.3.3"
"typescript": "^5.3.3",
"@rhtml/di": "^0.0.132"
},
"author": "Kristiyan Tachev",
"license": "MIT",
Expand All @@ -40,4 +40,4 @@
"types": "./dist/index.d.ts",
"module": "./dist/index.js",
"typings": "./dist/index.d.ts"
}
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -624,10 +624,10 @@
"@nodelib/fs.scandir" "2.1.5"
fastq "^1.6.0"

"@rhtml/di@^0.0.128":
version "0.0.128"
resolved "https://registry.yarnpkg.com/@rhtml/di/-/di-0.0.128.tgz#c6d612e156882a629bd270ea2447274eb3194f8b"
integrity sha512-GdaTT0OZcIiE6wtUJ1JLQMvsl1xgdwp57bmkfkQcHy4WwnA+cw51RLfFkKsGecfwS5eTkIgGteJ8ID+64K4W+g==
"@rhtml/di@^0.0.132":
version "0.0.132"
resolved "https://registry.yarnpkg.com/@rhtml/di/-/di-0.0.132.tgz#5ef136e7c4cae06cb3f1ef72ae5b33504aa4d3c3"
integrity sha512-a8RFZhTEdsZdbpZYXC117YzHjvwxbYzwmctEd5MOT8RJpYkIScjoyK35BD2fRMA24n1ZnVSDjJQxgnR+1J6FBQ==

"@rhtml/schematics@^0.0.128":
version "0.0.128"
Expand Down

0 comments on commit 8188adf

Please sign in to comment.