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

How to handle API urls. #360

Closed
Sharique-Hasan opened this issue Mar 24, 2018 · 2 comments
Closed

How to handle API urls. #360

Sharique-Hasan opened this issue Mar 24, 2018 · 2 comments
Labels

Comments

@Sharique-Hasan
Copy link

How to handle API path for Web and Ionic. I have my all api requests in libs. And Web part doesn't need IP address where as Ionic App needs IP address. How do I differ in between them?

@jeffbcross
Copy link
Member

You could have an APIModule that takes an argument for the address, and initialize it in both your Web app and Ionic app.

libs/api/src/api.module.ts

export const API_HOST = new InjectionToken('API_HOST');

@NgModule()
export class ApiModule {
  static forRoot(host: string) {
    return {
      ngModule: ApiModule,
      providers: [{
        provide: API_HOST,
        useValue: host
      }]
    }
  }
}

apps/mobile/src/app.module.ts

imports: [
  ApiModule.forRoot(SOME_IP_ADDRESS)
]

apps/web/src/app.module.ts

imports: [
  ApiModule.forRoot('')
]

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants