-
Notifications
You must be signed in to change notification settings - Fork 0
[25.07.19 / TASK-212] Feature - cache layer, 모듈 추가 #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 10 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
41f0f84
feature: cache module 초기 세팅 및 추가
Nuung fbfb886
modify: 디렉토리 세팅 변경
Nuung 2b4e3fd
feature: redis cache class 추가와 jsdocs 추가
Nuung 0e91a61
feature: module 하위 test 디렉토리 분리, cache index 추가
Nuung ea8337f
feature: cache instance 랑 index 대신 src config 활용
Nuung f29e3cd
feature: 추후 Ops 를 위한 헬스 체크 세팅, app.ts 리뉴얼
Nuung 40d531a
modify: 린팅
Nuung 58ddfa6
modify: app import 수정
Nuung 25495ca
feature: cache layer, redis 에 대한 unit test 추가
Nuung e40f352
modify: post service 계층 캐시 추가 예시
Nuung 5c51bdf
modify: 잔잔한 버그 수정과 리더보드 통합 E2E 테스트는 잠깐 skip 처리
Nuung 26d27fd
modify: redis cache JSON.parse 이슈 세부 처리와 예상치 못한 오류에 대한 grace-full exit
Nuung 7271f33
hotfix
Nuung 672694f
hotfix linting
Nuung 9b1029f
modify: redis 구현채, SCAN 으로 블록킹 완화
Nuung 905beff
modify: unhandledRejection 의 gracefulShutdown 메시지 수정
Nuung a208007
modify: index 에서 gracefulShutdown 발생시 cache connection 끊기 추가, 그에 따라 모…
Nuung 2937659
modify: disconn 대신 destroy, log warning 강화
Nuung d0af9d6
modify: destroy 도입에 따른 test 와 config 값 변경
Nuung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,92 @@ | ||
import 'reflect-metadata'; | ||
import express, { Application } from 'express'; | ||
import express, { Application, Request, Response, NextFunction } from 'express'; | ||
import dotenv from 'dotenv'; | ||
import cors from 'cors'; | ||
import cookieParser from 'cookie-parser'; | ||
import router from './routes'; | ||
import swaggerUi from 'swagger-ui-express'; | ||
import swaggerJSDoc from 'swagger-jsdoc'; | ||
|
||
import logger from '@/configs/logger.config'; | ||
import router from '@/routes'; | ||
import { NotFoundError } from '@/exception'; | ||
|
||
import { options } from '@/configs/swagger.config'; | ||
import { errorHandlingMiddleware } from './middlewares/errorHandling.middleware'; | ||
import { NotFoundError } from './exception'; | ||
import { initSentry } from '@/configs/sentry.config'; | ||
import { initSentry, getSentryStatus } from '@/configs/sentry.config'; | ||
import { initCache, getCacheStatus } from '@/configs/cache.config'; | ||
import { errorHandlingMiddleware } from '@/middlewares/errorHandling.middleware'; | ||
|
||
dotenv.config(); | ||
|
||
// Sentry 초기화 | ||
initSentry(); | ||
initSentry(); // Sentry 초기화 | ||
initCache(); // Redis 캐시 초기화 | ||
|
||
const app: Application = express(); | ||
|
||
// 실제 클라이언트 IP를 알기 위한 trust proxy 설정 | ||
app.set('trust proxy', true); | ||
app.set('trust proxy', process.env.NODE_ENV === 'production'); | ||
|
||
const swaggerSpec = swaggerJSDoc(options); | ||
|
||
app.use(cookieParser()); | ||
app.use(express.json()); | ||
app.use(express.urlencoded({ extended: true })); | ||
app.use(express.json({ limit: '10mb' })); // 파일 업로드 대비 | ||
app.use(express.urlencoded({ extended: true, limit: '10mb' })); | ||
|
||
app.use( | ||
cors({ | ||
origin: process.env.NODE_ENV === 'production' ? process.env.ALLOWED_ORIGINS?.split(',') : 'http://localhost:3000', | ||
origin: process.env.NODE_ENV === 'production' | ||
? process.env.ALLOWED_ORIGINS?.split(',').map(origin => origin.trim()) | ||
: 'http://localhost:3000', | ||
methods: ['GET', 'POST'], | ||
allowedHeaders: ['Content-Type', 'Authorization', 'Cookie', 'access_token', 'refresh_token'], | ||
credentials: true, | ||
}), | ||
); | ||
|
||
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec)); | ||
// 헬스체크 엔드포인트 | ||
app.get('/health', async (req: Request, res: Response) => { | ||
// 기본 정보 | ||
const healthData = { | ||
status: 'OK', | ||
timestamp: new Date().toISOString(), | ||
uptime: process.uptime(), | ||
environment: process.env.NODE_ENV, | ||
services: { | ||
sentry: false, | ||
cache: false | ||
} | ||
}; | ||
|
||
// Sentry 상태 확인 | ||
try { | ||
healthData.services.sentry = getSentryStatus(); | ||
} catch (error) { | ||
healthData.services.sentry = false; | ||
logger.error('Failed to health check for sentry:', error); | ||
} | ||
|
||
// Cache 상태 확인 | ||
try { | ||
healthData.services.cache = await getCacheStatus(); | ||
} catch (error) { | ||
healthData.services.cache = false; | ||
logger.error('Failed to health check for cache:', error); | ||
} | ||
|
||
res.status(200).json(healthData); | ||
}); | ||
|
||
// Swagger는 개발 환경에서만 | ||
if (process.env.NODE_ENV !== 'production') { | ||
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec)); | ||
} | ||
|
||
app.use('/api', router); | ||
app.use((req) => { | ||
throw new NotFoundError(`${req.url} not found`); | ||
|
||
// 404 에러 핸들링 수정 (throw 대신 next 사용) | ||
app.use((req: Request, res: Response, next: NextFunction) => { | ||
next(new NotFoundError(`${req.url} not found`)); | ||
}); | ||
|
||
app.use(errorHandlingMiddleware); | ||
|
||
export default app; | ||
export default app; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.