58 lines
1.5 KiB
TypeScript
58 lines
1.5 KiB
TypeScript
import { ValidationPipe, VersioningType } from '@nestjs/common';
|
|
import { NestFactory } from '@nestjs/core';
|
|
import type { NestExpressApplication } from '@nestjs/platform-express';
|
|
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
|
import { AppModule } from './app.module';
|
|
|
|
export const API_JSON_BODY_LIMIT = '2mb';
|
|
|
|
export async function createApp(): Promise<NestExpressApplication> {
|
|
const app = await NestFactory.create<NestExpressApplication>(AppModule, {
|
|
bufferLogs: true,
|
|
bodyParser: false,
|
|
});
|
|
|
|
// Upload finalize requests can include base64 artwork payloads.
|
|
app.useBodyParser('json', { limit: API_JSON_BODY_LIMIT });
|
|
app.useBodyParser('urlencoded', {
|
|
extended: true,
|
|
limit: API_JSON_BODY_LIMIT,
|
|
});
|
|
|
|
app.setGlobalPrefix('api');
|
|
app.enableVersioning({
|
|
type: VersioningType.URI,
|
|
});
|
|
app.useGlobalPipes(
|
|
new ValidationPipe({
|
|
whitelist: true,
|
|
forbidNonWhitelisted: true,
|
|
transform: true,
|
|
}),
|
|
);
|
|
|
|
const document = SwaggerModule.createDocument(
|
|
app,
|
|
new DocumentBuilder()
|
|
.setTitle('Velody API')
|
|
.setDescription('Velody Phase 1 foundation API')
|
|
.setVersion('1.0.0')
|
|
.addBearerAuth(
|
|
{
|
|
type: 'http',
|
|
scheme: 'bearer',
|
|
bearerFormat: 'Bearer',
|
|
description: 'Device access token',
|
|
},
|
|
'bearer',
|
|
)
|
|
.build(),
|
|
);
|
|
|
|
SwaggerModule.setup('api/docs', app, document, {
|
|
jsonDocumentUrl: 'api/docs-json',
|
|
});
|
|
|
|
return app;
|
|
}
|