-
Notifications
You must be signed in to change notification settings - Fork 2
Sandbox 251102 (killerwhale) #307
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
Changes from all commits
bbcf7f5
d7cb32d
0ac661b
d68b997
daedcde
6941ad8
dfe93c8
af02288
00c4369
8633b29
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { createParamDecorator, ExecutionContext } from '@nestjs/common' | ||
|
|
||
| export const GetLanguage = createParamDecorator((_data, ctx: ExecutionContext): string => { | ||
| const req = ctx.switchToHttp().getRequest() | ||
| const acceptLanguageHeader = req.headers['accept-language'] | ||
|
|
||
| if (typeof acceptLanguageHeader !== 'string' || !acceptLanguageHeader) { | ||
| return 'kr' | ||
| } | ||
|
|
||
| const languages = acceptLanguageHeader.split(',').map((langPart) => langPart.trim().split(';')[0].toLowerCase()) | ||
|
|
||
| if (languages.some((lang) => lang.startsWith('ko'))) { | ||
| return 'kr' | ||
| } | ||
|
|
||
| return 'en' | ||
| }) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 코드 검토 댓글이 코드는
이러한 점들을 개선하면 코드의 가독성과 유지보수성을 높일 수 있을 것입니다. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
코드 검토 댓글
이 코드는
@nestjs/common에서 네스트JS 용으로 작성된 파라미터 데코레이터GetLanguage를 정의하고 있습니다. 아래의 몇 가지 문제점과 개선 사항을 제시합니다:기본 언어 설정: 현재 코드는
accept-language헤더가 비어있거나 문자열이 아닐 경우 기본 언어로 'kr'을 반환합니다. 하지만, 다른 언어 선택이 필요할 수 있습니다. 이 기능에 대한 설정을 외부에서 주입할 수 있도록 고려해보세요.헤더 검사:
req.headers['accept-language']에서 직접 헤더를 가져오고 있지만, 'accept-language' 헤더가 아예 존재하지 않는 경우도 발생할 수 있습니다. 따라서 아래와 같은 변형을 고려해보세요:이렇게 하면 기존 코드를 간단히 유지하면서 더 안전한 확인을 할 수 있습니다.
확장성 문제: 현재 코드는 한국어(
kr)와 영어(en)만 지원하고 있습니다. 만약 다른 언어를 추가하게 된다면, this may lead to a complex condition structure or significant changes in the code. 이를 해결하기 위해 language mapping 시스템을 도입해보세요.타입 안전성: TypeScript의 강점을 활용하여
acceptLanguageHeader의 타입을 더 명확히 해주는 것도 좋습니다.string | undefined와 같은 강력한 타입을 고려해보세요.코드 문서화: 기능을 명시적으로 설명하는 주석을 추가하여 코드 유지보수성을 높여야 합니다. 특히 팀원이 이해하는 데 도움을 줄 수 있습니다.
이러한 점들을 개선하면 코드의 가독성과 유지보수성을 높일 수 있을 것입니다.