@nestify-js/shared 0.2.4 → 0.2.6
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/README.md +61 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -286,10 +286,65 @@ class ApiController {
|
|
|
286
286
|
}
|
|
287
287
|
```
|
|
288
288
|
|
|
289
|
-
|
|
289
|
+
### Application Bootstrap
|
|
290
|
+
|
|
291
|
+
#### `nestify(rootModule, options?)` (recommended)
|
|
292
|
+
|
|
293
|
+
Creates the fastify instance, registers fastify plugins, applies all modules and (optionally) starts listening — all in one call. Returns the underlying fastify instance.
|
|
294
|
+
|
|
295
|
+
```typescript
|
|
296
|
+
import { nestify } from 'nestify-js';
|
|
297
|
+
|
|
298
|
+
const app = await nestify(AppModule, {
|
|
299
|
+
// shortcut for `fastify.logger`
|
|
300
|
+
logger: { level: 'info' },
|
|
301
|
+
|
|
302
|
+
// fastify plugins registered before modules are applied
|
|
303
|
+
// - tuple form: `[plugin]` or `[plugin, options]`
|
|
304
|
+
plugins: [
|
|
305
|
+
[multipart, { limits: { fileSize: 10 * 1024 * 1024 } }],
|
|
306
|
+
[staticFiles, { root: './public', prefix: '/' }],
|
|
307
|
+
],
|
|
308
|
+
|
|
309
|
+
// setup callback to register auto-created instances
|
|
310
|
+
// - e.g. the built-in `setupBasicPipes` creates preset pipe instances
|
|
311
|
+
setup: setupBasicPipes,
|
|
312
|
+
|
|
313
|
+
// start listening after all modules are registered
|
|
314
|
+
// - `true` uses the `PORT` / `HOST` env vars (falling back to 3000 / 0.0.0.0)
|
|
315
|
+
listen: true,
|
|
316
|
+
// or override: listen: { port: 8080, host: 'localhost' }
|
|
317
|
+
});
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
Available options:
|
|
321
|
+
|
|
322
|
+
| Option | Type | Description |
|
|
323
|
+
| --- | --- | --- |
|
|
324
|
+
| `logger` | `FastifyServerOptions['logger']` | Shortcut for `fastify.logger` |
|
|
325
|
+
| `fastify` | `FastifyServerOptions` | Options passed to the fastify factory (`fastify(options)`) |
|
|
326
|
+
| `plugins` | `readonly [plugin, options?][]` | Fastify plugins registered before modules are applied (callback-style and async-style are both accepted) |
|
|
327
|
+
| `setup` | `(register: (cls: Constructor) => void) => void` | Setup callback to register auto-created instances (e.g. `setupBasicPipes`) |
|
|
328
|
+
| `listen` | `boolean \| Partial<FastifyListenOptions>` | Start listening after all modules are registered |
|
|
329
|
+
| `allowCrossModuleCircularReference` | `boolean` | Must be `true` to allow **cross-module** circular dependencies (same-module circular references are always allowed). `@default false` |
|
|
330
|
+
|
|
331
|
+
#### `apply(app, options)`
|
|
332
|
+
|
|
333
|
+
If you need more control over the fastify instance (custom plugins, hooks, decorators...), create it yourself and use the lower-level `apply()` instead:
|
|
290
334
|
|
|
291
335
|
```typescript
|
|
292
336
|
import fastify from 'fastify';
|
|
337
|
+
import { apply } from 'nestify-js';
|
|
338
|
+
|
|
339
|
+
const app = fastify({ logger: true });
|
|
340
|
+
|
|
341
|
+
await apply(app, { rootModule: AppModule });
|
|
342
|
+
await app.listen({ port: 3000 });
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
## Complete Usage Example
|
|
346
|
+
|
|
347
|
+
```typescript
|
|
293
348
|
import {
|
|
294
349
|
Module,
|
|
295
350
|
Controller,
|
|
@@ -301,7 +356,7 @@ import {
|
|
|
301
356
|
Params,
|
|
302
357
|
UseGuards,
|
|
303
358
|
Guard,
|
|
304
|
-
|
|
359
|
+
nestify,
|
|
305
360
|
} from 'nestify-js';
|
|
306
361
|
|
|
307
362
|
// Service
|
|
@@ -377,14 +432,11 @@ class UserController {
|
|
|
377
432
|
})
|
|
378
433
|
class AppModule {}
|
|
379
434
|
|
|
380
|
-
// Application
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
rootModule: AppModule,
|
|
435
|
+
// Application bootstrap
|
|
436
|
+
await nestify(AppModule, {
|
|
437
|
+
logger: true,
|
|
438
|
+
listen: true, // uses the `PORT` / `HOST` env vars, defaults to 3000 / 0.0.0.0
|
|
385
439
|
});
|
|
386
|
-
|
|
387
|
-
await app.listen({ port: 3000 });
|
|
388
440
|
console.log('Server running on http://localhost:3000');
|
|
389
441
|
```
|
|
390
442
|
|