25 lines
959 B
TypeScript
25 lines
959 B
TypeScript
import 'reflect-metadata';
|
|
import { ModuleRef, NestFactory, Reflector } from '@nestjs/core';
|
|
import { AppModule } from './app.module';
|
|
import { ValidationPipe } from '@nestjs/common';
|
|
import { JwtAuthGuard } from './modules/authentication/guards/jwt-auth.guard';
|
|
import { RolesGuard } from './common/guards/roles.guard';
|
|
import { OwnershipGuard } from './common/guards/ownership.guard';
|
|
|
|
async function bootstrap() {
|
|
const app = await NestFactory.create(AppModule);
|
|
//setup Reflector for Roles()
|
|
const reflector = app.get(Reflector);
|
|
|
|
app.useGlobalPipes(
|
|
new ValidationPipe({ whitelist: true, transform: true}));
|
|
app.useGlobalGuards(
|
|
new JwtAuthGuard(reflector), //Authentification JWT
|
|
new RolesGuard(reflector), //deny-by-default and Role-based Access Control
|
|
new OwnershipGuard(reflector, app.get(ModuleRef)), //Global use of OwnershipGuard, not implemented yet
|
|
);
|
|
|
|
await app.listen(process.env.PORT ?? 3000);
|
|
}
|
|
bootstrap();
|