Skip to content
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

Fix/#38 JS SDK가 브라우저에서 동작하지 않는 이슈 #39

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion sdk/js/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class LogBat {
private static appId: string = '';
private static apiEndpoint: string = 'https://api.logbat.info/log';
private static apiEndpoint: string = 'https://api.logbat.info/logs';
private static originalConsole: { log: typeof console.log; error: typeof console.error };
private static isInitialized: boolean = false;

Expand Down Expand Up @@ -70,4 +70,8 @@ class LogBat {
}
}

if (typeof window !== 'undefined') {
(window as any).LogBat = LogBat;
}

export default LogBat;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코드 패치를 검토한 결과는 다음과 같습니다:

  1. 버그 위험:

    • apiEndpoint 변경이 기존 API와의 호환성을 깨뜨릴 수 있습니다. 이전 엔드포인트를 사용하는 코드가 있을 경우, 이로 인해 요청이 실패할 수 있습니다. 변경에 대한 문서화가 필요합니다.
  2. 개선 제안:

    • 상수 사용: apiEndpoint를 클래스 내부의 상수로 선언하는 것이 좋습니다. 타입을 명시함으로써 향후 코드 유지보수가 용이해집니다.
    • 주석 추가: 중요한 변경 사항이나 의도를 주석으로 명시하면 후속 개발자가 이해하기 쉬워집니다.
    • 타입 정의: window as any 대신 안전한 방식으로 객체 속성을 확장하는 것이 좋습니다. 이를 위해 적절한 타입 정의를 통해 TypeScript의 타입 안전을 활용할 수 있습니다.
  3. 형식 개선:

    • 꼭 필요한 경우가 아니라면 파일 끝에 공백 줄을 추가하는 것도 좋습니다. 이는 특정 형식을 유지하는 데 도움이 됩니다.

결과적으로, 변경 사항은 유익하지만 기존 시스템과의 연결성을 유지하도록 주의해야 하며, 코드 가독성을 높일 수 있는 여지가 있습니다.

10 changes: 7 additions & 3 deletions sdk/js/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ module.exports = (env, argv) => {
output: {
filename: isProduction ? 'sdk.min.js' : 'sdk.js',
path: path.resolve(__dirname, 'dist'),
library: 'LogBat',
libraryTarget: 'umd',
globalObject: 'this'
library: {
name: 'LogBat',
type: 'umd',
export: 'default'
},
globalObject: 'this',
umdNamedDefine: true
},
devtool: isProduction ? 'source-map' : 'eval-source-map',
mode: isProduction ? 'production' : 'development',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코드 패치를 검토해보면 다음과 같은 개선 사항 및 버그 리스크를 제안할 수 있습니다:

  1. 구조 개선: library 설정을 객체로 변경한 것은 더 명확하고 확장성이 좋습니다. 이 점은 긍정적입니다.

  2. Type 정의: type: 'umd'로 변경한 것도 장점이지만, UMD에 대한 정의가 필요할 경우 문서나 주석 추가를 고려하는 것이 좋습니다.

  3. 버전 호환성: 사용하는 빌드 도구의 버전에 따라 umdNamedDefine 속성이 지원되지 않을 수 있으니, 해당 옵션의 지원 여부를 확인해야 합니다.

  4. 불필요한 프로퍼티: 만약 export: 'default'가 실제로 필요한 설정이라면 괜찮지만, 아니라면 코드 복잡성을 유발할 수 있으므로 사용 목적을 재검토할 필요가 있습니다.

  5. 개발 모드와 생산 모드: devtool 설정에서 모드에 따라 다른 소스 맵을 지정하는 것은 좋지만, 생산 모드에서는 성능을 고려해 더 경량화된 구성도 검토하는 것이 좋습니다.

종합적으로 보았을 때, 긍정적인 방향으로 변화하고 있으며, 몇 가지 세부 사항을 조정하면 더욱 안정적이고 효율적인 코드가 될 것입니다.

Expand Down