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

(feat): NCNetwork : baseUrl 기능 추가 #7

Merged
merged 6 commits into from Mar 25, 2022

Conversation

kghdcode
Copy link
Contributor

작업내용

  • NCNetworking의 구현체(예시 : AxiosNetworking)는 baseUrl을 필수로 받아야 합니다. 이와 함께 baseUrl을 변경하기 위한 setNewBaseUrl()을 구현해야 합니다.
  • NCNetwork : string? 타입의 baseUrl를 받을 수 있습니다. 이 값이 있다면 NCNetworking의 baseUrl을 변경할 수 있습니다.
  • NCNetworking.execute()에서는 baseUrl을 기본으로 가지고 있으므로, NCNetwork에서는 url의 뒷부분만을 넘겨주면 됩니다.
  • example에 위 사항이 적용되도록 반영했습니다. (테스트 역시 진행했습니다.)

Copy link
Contributor

@iamchiwon-ncode iamchiwon-ncode left a comment

Choose a reason for hiding this comment

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

baseUrl이 설정된 상태에서 baseUrl을 기반으로 하지 않는 URL과 통신해야 할 때는 어떻게 해야 하나요?

@@ -10,6 +10,12 @@ import { NCNetworkException } from "./NCNetworkException";
export class NCNetwork {
private network: NCNetworking = Inject(NCNetworkingClassName);

constructor(baseUrl?: string) {
if (baseUrl?.trim()) {
this.network.setNewBaseUrl(baseUrl);
Copy link
Contributor

Choose a reason for hiding this comment

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

유효성을 판단할때는 trim을 하는데, set할 때는 trim을 안하나요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

setNewBaseUrl()에서 baseUrl을 trim() 처리해서 사용하도록 수정했습니다.

this.network.setNewBaseUrl(baseUrl?.trim());

@kghdcode
Copy link
Contributor Author

baseUrl이 설정된 상태에서 baseUrl을 기반으로 하지 않는 URL과 통신해야 할 때는 어떻게 해야 하나요?

@iamchiwon-ncode
baseUrl을 기반으로 하지 않는 다른 url과 통신하려면, new NCNetwork().get(url) 위치에 그 다른 url이 들어올 것이라고 생각합니다.

new NCNetwork()에는 아무 값도 넣지 않으면 baseUrl이 사용되기 때문에, 일부러 빈 문자열을 넣어주고 constructor에서 trim()을 if로 판단하는 로직을 제거한다면 baseUrl을 빈 문자열로 교체할 수 있겠습니다.

이렇게 되면 AxiosNetworking.execute()에서 config의 url을 ${this._baseUrl}${url} 이렇게 합쳐 주고 있으므로, '빈 문자열 + 다른 url'로 요청할 수 있지 않을까 합니다.

@iamchiwon-ncode
Copy link
Contributor

iamchiwon-ncode commented Mar 18, 2022

@kghdcode

// baseUrl 을 사용하고 싶을 때 
new NCNetwork().get('/path');
// custom Url 을 사용하고 싶을 때 
new NCNetwork().get("http://other");

이렇게 사용하고 싶은겁니다. 지금 구현으로는 서버를 바꿔가면서 계속 baseUrl이 덮어씌워지니까 매번 full path를 사용해야 하는 상황이죠.

@kghdcode
Copy link
Contributor Author

테스트 코드를 추가해서 커밋했습니다.

@kghdcode
Copy link
Contributor Author

@iamchiwon-ncode 앞선 커밋의 코드를 수정하여, example에서 테스트코드를 작성했습니다.

@iamchiwon iamchiwon merged commit 0e0e00a into ncodeofficial:main Mar 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants