Created
September 27, 2017 02:04
-
-
Save jiaming0708/25ba9d7843e91d147d48f9bff96fbc65 to your computer and use it in GitHub Desktop.
ionic proxy config
This file contains 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
import { Platform } from 'ionic-angular'; | |
import { InjectionToken, Injectable } from "@angular/core"; | |
export let APP_CONFIG = new InjectionToken<string>('apiConfig'); | |
export function APIConfig(plat: Platform) { | |
const _browser = '/api'; // reverse proxy | |
const _device = 'http://192.168.0.100/api'; | |
return plat.is('core') ? _browser : _device; | |
} |
This file contains 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
import { APP_CONFIG, APIConfig } from "./../services/APIConfig"; | |
import { IonicApp, IonicErrorHandler, IonicModule, Platform } from 'ionic-angular'; | |
@NgModule({ | |
providers: [ | |
{ provide: APP_CONFIG, useFactory: APIConfig, deps: [Platform] } | |
] | |
}) | |
export class AppModule {} |
This file contains 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
@Injectable() | |
export class AppService { | |
constructor(@Inject(APP_CONFIG) endPoint:string) { | |
this.endPoint = endPoint; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment