chore(api): scaffold NestJS application
This commit is contained in:
1 parent
7a2b0a15d7
commit
05565f5a44
14 files changed
+378
No files matched your search
@@ -0,0 +1,22 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
|
||||
describe('AppController', () => {
|
||||
let appController: AppController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const app: TestingModule = await Test.createTestingModule({
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
}).compile();
|
||||
|
||||
appController = app.get<AppController>(AppController);
|
||||
});
|
||||
|
||||
describe('root', () => {
|
||||
it('should return "Hello World!"', () => {
|
||||
expect(appController.getHello()).toBe('Hello World!');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { AllowPublicAccess } from './modules/auth/allow-public-access.decorator';
|
||||
import { AppService } from './app.service';
|
||||
|
||||
@Controller()
|
||||
export class AppController {
|
||||
constructor(private readonly appService: AppService) {}
|
||||
|
||||
@Get()
|
||||
@AllowPublicAccess()
|
||||
getHello(): string {
|
||||
return this.appService.getHello();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { AuctionModule } from './modules/auction/auction.module';
|
||||
import { AuthModule } from './modules/auth/auth.module';
|
||||
import { CommunityModule } from './modules/community/community.module';
|
||||
import { CommunityStatsModule } from './modules/community-stats/community-stats.module';
|
||||
import { DakaoModule } from './modules/dakao/dakao.module';
|
||||
import { GlobalModule } from './modules/global/global.module';
|
||||
import { LegacyImportModule } from './modules/legacy-import/legacy-import.module';
|
||||
import { MatchHistoryModule } from './modules/match-history/match-history.module';
|
||||
import { MatchModule } from './modules/match/match.module';
|
||||
import { RiotModule } from './modules/riot/riot.module';
|
||||
import { TournamentCodeModule } from './modules/tournament-code/tournament-code.module';
|
||||
import { TournamentResultModule } from './modules/tournament-result/tournament-result.module';
|
||||
import { UserModule } from './modules/user/user.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot({
|
||||
isGlobal: true,
|
||||
envFilePath: ['../project.env', 'project.env'],
|
||||
}),
|
||||
GlobalModule,
|
||||
AuthModule,
|
||||
RiotModule,
|
||||
CommunityModule,
|
||||
CommunityStatsModule,
|
||||
MatchModule,
|
||||
MatchHistoryModule,
|
||||
LegacyImportModule,
|
||||
TournamentCodeModule,
|
||||
TournamentResultModule,
|
||||
AuctionModule,
|
||||
UserModule,
|
||||
DakaoModule,
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
})
|
||||
export class AppModule {}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
getHello(): string {
|
||||
return 'Hello World!';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { ValidationPipe } from '@nestjs/common';
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { AppModule } from './app.module';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule, {
|
||||
rawBody: true,
|
||||
});
|
||||
|
||||
const isDev = process.env.NODE_ENV === 'dev';
|
||||
const webOrigins = process.env.WEB_ORIGIN?.split(',').map((origin) =>
|
||||
origin.trim(),
|
||||
) ?? [
|
||||
'http://localhost:5173',
|
||||
'http://126.dahyeon.us:5173',
|
||||
'https://lolympus.dahyeon.us',
|
||||
];
|
||||
|
||||
app.enableCors({
|
||||
origin: isDev ? true : webOrigins,
|
||||
credentials: true,
|
||||
allowedHeaders: ['Authorization', 'Content-Type', 'X-Auth-User-Id'],
|
||||
});
|
||||
app.useGlobalPipes(
|
||||
new ValidationPipe({
|
||||
whitelist: true,
|
||||
forbidNonWhitelisted: true,
|
||||
transform: true,
|
||||
transformOptions: { enableImplicitConversion: false },
|
||||
}),
|
||||
);
|
||||
await app.listen(isDev ? 3000 : 10712);
|
||||
}
|
||||
bootstrap();
|
||||
Reference in new issue
Block a user