From 7cde555beff94e8c32f8242746a06f8df8356e6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EB=8B=A4=ED=98=84=20=28Dahyeon=20Park=29?= Date: Sun, 5 Apr 2026 01:43:00 +0900 Subject: [PATCH] feat(api): add app bootstrap --- apps/api/src/app.controller.spec.ts | 22 +++++++++++++++++++ apps/api/src/app.controller.ts | 14 ++++++++++++ apps/api/src/app.service.ts | 8 +++++++ apps/api/src/main.ts | 34 +++++++++++++++++++++++++++++ apps/api/test/app.e2e-spec.ts | 29 ++++++++++++++++++++++++ apps/api/test/jest-e2e.json | 9 ++++++++ 6 files changed, 116 insertions(+) create mode 100644 apps/api/src/app.controller.spec.ts create mode 100644 apps/api/src/app.controller.ts create mode 100644 apps/api/src/app.service.ts create mode 100644 apps/api/src/main.ts create mode 100644 apps/api/test/app.e2e-spec.ts create mode 100644 apps/api/test/jest-e2e.json diff --git a/apps/api/src/app.controller.spec.ts b/apps/api/src/app.controller.spec.ts new file mode 100644 index 00000000..d22f3890 --- /dev/null +++ b/apps/api/src/app.controller.spec.ts @@ -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); + }); + + describe('root', () => { + it('should return "Hello World!"', () => { + expect(appController.getHello()).toBe('Hello World!'); + }); + }); +}); diff --git a/apps/api/src/app.controller.ts b/apps/api/src/app.controller.ts new file mode 100644 index 00000000..64b83aaf --- /dev/null +++ b/apps/api/src/app.controller.ts @@ -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(); + } +} diff --git a/apps/api/src/app.service.ts b/apps/api/src/app.service.ts new file mode 100644 index 00000000..927d7cca --- /dev/null +++ b/apps/api/src/app.service.ts @@ -0,0 +1,8 @@ +import { Injectable } from '@nestjs/common'; + +@Injectable() +export class AppService { + getHello(): string { + return 'Hello World!'; + } +} diff --git a/apps/api/src/main.ts b/apps/api/src/main.ts new file mode 100644 index 00000000..9efa99fa --- /dev/null +++ b/apps/api/src/main.ts @@ -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(); diff --git a/apps/api/test/app.e2e-spec.ts b/apps/api/test/app.e2e-spec.ts new file mode 100644 index 00000000..a767839c --- /dev/null +++ b/apps/api/test/app.e2e-spec.ts @@ -0,0 +1,29 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { INestApplication } from '@nestjs/common'; +import request from 'supertest'; +import { App } from 'supertest/types'; +import { AppModule } from './../src/app.module'; + +describe('AppController (e2e)', () => { + let app: INestApplication; + + beforeEach(async () => { + const moduleFixture: TestingModule = await Test.createTestingModule({ + imports: [AppModule], + }).compile(); + + app = moduleFixture.createNestApplication(); + await app.init(); + }); + + it('/ (GET)', () => { + return request(app.getHttpServer()) + .get('/') + .expect(200) + .expect('Hello World!'); + }); + + afterEach(async () => { + await app.close(); + }); +}); diff --git a/apps/api/test/jest-e2e.json b/apps/api/test/jest-e2e.json new file mode 100644 index 00000000..e9d912f3 --- /dev/null +++ b/apps/api/test/jest-e2e.json @@ -0,0 +1,9 @@ +{ + "moduleFileExtensions": ["js", "json", "ts"], + "rootDir": ".", + "testEnvironment": "node", + "testRegex": ".e2e-spec.ts$", + "transform": { + "^.+\\.(t|j)s$": "ts-jest" + } +}