2022-08-23 19:14:01 +02:00
|
|
|
import { Controller, Get, Module } from '@nestjs/common';
|
|
|
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
2022-08-25 20:22:32 +02:00
|
|
|
import { INode, JWTToken, User } from './entities';
|
2022-08-23 19:14:01 +02:00
|
|
|
import FileSystemModule from './modules/filesystem';
|
|
|
|
import { JWTAuthGuard, Role, RoleGuard } from './authguards';
|
|
|
|
import AuthModule from './modules/auth';
|
|
|
|
import { ServeStaticModule } from '@nestjs/serve-static';
|
|
|
|
import { join } from 'path';
|
2022-08-23 21:49:56 +02:00
|
|
|
import { cwd } from 'process';
|
2022-08-25 23:42:12 +02:00
|
|
|
import { UserRole } from '../dto/';
|
2022-08-23 19:14:01 +02:00
|
|
|
|
|
|
|
declare const PROD: boolean | undefined;
|
|
|
|
|
|
|
|
@Controller('test')
|
|
|
|
class TestController {
|
|
|
|
@Role(UserRole.USER)
|
|
|
|
@Get('hello')
|
|
|
|
getHello(): string {
|
|
|
|
return 'UwU';
|
|
|
|
}
|
|
|
|
|
|
|
|
@Role(UserRole.ADMIN)
|
|
|
|
@Get('hello2')
|
|
|
|
getHelloAdmin(): string {
|
|
|
|
return 'UwU Admin';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Module({
|
|
|
|
imports: [
|
|
|
|
TypeOrmModule.forRoot({
|
|
|
|
type: 'sqlite',
|
|
|
|
database: 'sqlite.db',
|
|
|
|
synchronize: true,
|
|
|
|
entities: [User, INode, JWTToken]
|
|
|
|
}),
|
|
|
|
ServeStaticModule.forRoot({
|
|
|
|
rootPath:
|
|
|
|
typeof PROD !== 'undefined' && PROD
|
2022-08-23 21:49:56 +02:00
|
|
|
? join(cwd(), 'frontend')
|
2022-08-23 19:14:01 +02:00
|
|
|
: join(__dirname, '..', '..', 'frontend', 'dist'),
|
|
|
|
exclude: ['/api*']
|
|
|
|
}),
|
|
|
|
FileSystemModule,
|
|
|
|
AuthModule
|
|
|
|
],
|
|
|
|
controllers: [TestController],
|
|
|
|
providers: [
|
|
|
|
{
|
|
|
|
provide: 'APP_GUARD',
|
|
|
|
useClass: JWTAuthGuard
|
|
|
|
},
|
|
|
|
{
|
|
|
|
provide: 'APP_GUARD',
|
|
|
|
useClass: RoleGuard
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
export class AppModule {}
|