-
Notifications
You must be signed in to change notification settings - Fork 43
/
main.ts
55 lines (52 loc) · 1.45 KB
/
main.ts
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
import { NestFactory } from "@nestjs/core";
import {
FastifyAdapter,
NestFastifyApplication,
} from "@nestjs/platform-fastify";
import headers from "fastify-helmet";
import fastifyRateLimiter from "fastify-rate-limit";
import { AppModule } from "./modules/app/app.module";
import { ValidationPipe } from "@nestjs/common";
import { SwaggerModule, DocumentBuilder } from "@nestjs/swagger";
/**
* The url endpoint for open api ui
* @type {string}
*/
export const SWAGGER_API_ROOT = "api/docs";
/**
* The name of the api
* @type {string}
*/
export const SWAGGER_API_NAME = "API";
/**
* A short description of the api
* @type {string}
*/
export const SWAGGER_API_DESCRIPTION = "API Description";
/**
* Current version of the api
* @type {string}
*/
export const SWAGGER_API_CURRENT_VERSION = "1.0";
(async () => {
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter({ logger: true }),
);
const options = new DocumentBuilder()
.setTitle(SWAGGER_API_NAME)
.setDescription(SWAGGER_API_DESCRIPTION)
.setVersion(SWAGGER_API_CURRENT_VERSION)
.addBearerAuth()
.build();
const document = SwaggerModule.createDocument(app, options);
SwaggerModule.setup(SWAGGER_API_ROOT, app, document);
app.enableCors();
app.register(headers);
app.register(fastifyRateLimiter, {
max: 100,
timeWindow: 60000,
});
app.useGlobalPipes(new ValidationPipe());
await app.listen(9000, "0.0.0.0");
})();