53 lines
1.1 KiB
TypeScript
53 lines
1.1 KiB
TypeScript
|
import { Controller, Get, Module } from '@nestjs/common';
|
||
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||
|
import { INode, JWTToken, User, UserRole } from './entities';
|
||
|
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';
|
||
|
|
||
|
@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: join(__dirname, '..', '..', 'frontend', 'dist'),
|
||
|
exclude: ['/api*']
|
||
|
}),
|
||
|
FileSystemModule,
|
||
|
AuthModule
|
||
|
],
|
||
|
controllers: [TestController],
|
||
|
providers: [
|
||
|
{
|
||
|
provide: 'APP_GUARD',
|
||
|
useClass: JWTAuthGuard
|
||
|
},
|
||
|
{
|
||
|
provide: 'APP_GUARD',
|
||
|
useClass: RoleGuard
|
||
|
}
|
||
|
]
|
||
|
})
|
||
|
export class AppModule {}
|