-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.mts
More file actions
97 lines (87 loc) · 2.05 KB
/
app.mts
File metadata and controls
97 lines (87 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* @file app
* @module sneusers/app
*/
import useSwagger from '#hooks/use-swagger.hook'
import AppModule from '#modules/app.module'
import { ConsoleLogger } from '@nestjs/common'
import { NestFactory } from '@nestjs/core'
import {
FastifyAdapter,
type NestFastifyApplication
} from '@nestjs/platform-fastify'
import type { FastifyReply } from 'fastify'
export default app
/**
* Create a NestJS application.
*
* @see {@linkcode NestFastifyApplication}
* @see https://fastify.dev
*
* @todo versioning
*
* @async
*
* @this {void}
*
* @return {Promise<NestFastifyApplication>}
* NestJS x Fastify application
*/
async function app(this: void): Promise<NestFastifyApplication> {
/**
* The NestJS application.
*
* @const {NestFastifyApplication} app
*/
const app: NestFastifyApplication = await NestFactory.create(
AppModule,
new FastifyAdapter(),
{
abortOnError: false,
logger: new ConsoleLogger({ logLevels: ['verbose'], prefix: 'nest' })
}
)
// decorate the fastify response object.
app
.getHttpAdapter()
.getInstance()
.decorateReply('end', end) // required for @nestjs/passport
.decorateReply('setHeader', setHeader) // required for @nestjs/passport
// configure openapi documentation endpoints.
useSwagger(app)
return app
}
/* v8 ignore start */
/**
* Signal that no more data will be written.
*
* @this {FastifyReply}
*
* @return {undefined}
*/
function end(this: FastifyReply): undefined {
return void this.raw.end()
}
/**
* Set a single header value.
*
* If the header already exists in the to-be-sent headers, its value will be
* replaced.
* Use an array of strings to send multiple headers with the same name.
*
* @this {FastifyReply}
*
* @param {string} key
* The header name
* @param {ReadonlyArray<string> | number | string} value
* The header value
* @return {undefined}
*/
function setHeader(
this: FastifyReply,
key: string,
value: number | string | readonly string[]
): undefined {
return void this.raw.setHeader(key, value)
}
/* v8 ignore end */