interface NestFastifyApplication extends INestApplication {
register<Options extends FastifyPluginOptions = any>(plugin: any, opts?: FastifyRegisterOptions<Options>): Promise<FastifyInstance>
useBodyParser<TServer extends RawServerBase = RawServerBase>(type: string | RegExp | string[], options?: NestFastifyBodyParserOptions, parser?: FastifyBodyParser<Buffer, TServer>): this
useStaticAssets(options: FastifyStaticOptions): this
setViewEngine(options: string | FastifyViewOptions): this
inject(): LightMyRequestChain
listen(port: string | number, callback?: (err: Error, address: string) => void): Promise<any>
}
Methods
register()
|
A wrapper function around native fastify.register() method.
Example `app.register(require('@fastify/formbody'))
|
register<Options extends FastifyPluginOptions = any>(plugin: any, opts?: FastifyRegisterOptions<Options>): Promise<FastifyInstance>
Parameters
Option |
Type |
Description |
plugin
|
any |
|
opts
|
FastifyRegisterOptions |
Optional. Default is undefined .
|
Returns
Promise<FastifyInstance>
|
useBodyParser()
|
Register Fastify body parsers on the fly. Will respect
the application's rawBody option.
|
useBodyParser<TServer extends RawServerBase = RawServerBase>(type: string | RegExp | string[], options?: NestFastifyBodyParserOptions, parser?: FastifyBodyParser<Buffer, TServer>): this
Parameters
Option |
Type |
Description |
type
|
string | RegExp | string[] |
|
options
|
NestFastifyBodyParserOptions |
Optional. Default is undefined .
|
parser
|
FastifyBodyParser |
Optional. Default is undefined .
|
Examples
const app = await NestFactory.create(
AppModule,
new FastifyAdapter(),
{ rawBody: true }
);
app.useBodyParser('application/json', { bodyLimit: 50 * 1000 * 1024 });
Returns
this
|
useStaticAssets()
|
Sets a base directory for public assets.
Example app.useStaticAssets({ root: 'public' })
|
useStaticAssets(options: FastifyStaticOptions): this
Parameters
Option |
Type |
Description |
options
|
FastifyStaticOptions |
|
Returns
this
|
setViewEngine()
|
Sets a view engine for templates (views), for example: pug , handlebars , or ejs .
|
setViewEngine(options: string | FastifyViewOptions): this
Parameters
Option |
Type |
Description |
options
|
string | FastifyViewOptions |
|
Returns
this
|
Don't pass in a string. The string type in the argument is for compatibility reason and will cause an exception.
|
inject()
|
A wrapper function around native fastify.inject() method.
|
inject(opts: any): Promise<LightMyRequestResponse>
Parameters
Option |
Type |
Description |
opts
|
any |
|
Returns
Promise<LightMyRequestResponse>
|
listen()
|
Starts the application.
|
listen(port: string | number, address: string, callback?: (err: Error, address: string) => void): Promise<any>
Parameters
Option |
Type |
Description |
port
|
string | number |
|
address
|
string |
|
callback
|
(err: Error, address: string) => void |
Optional. Default is undefined .
|
Returns
Promise<any>
|
listen(port: string | number, address: string, backlog: number, callback?: (err: Error, address: string) => void): Promise<any>
Parameters
Option |
Type |
Description |
port
|
string | number |
|
address
|
string |
|
backlog
|
number |
|
callback
|
(err: Error, address: string) => void |
Optional. Default is undefined .
|
Returns
Promise<any>
|