Skip to content

Instantly share code, notes, and snippets.

@jiaming0708
Created September 27, 2017 02:04
Show Gist options
  • Save jiaming0708/25ba9d7843e91d147d48f9bff96fbc65 to your computer and use it in GitHub Desktop.
Save jiaming0708/25ba9d7843e91d147d48f9bff96fbc65 to your computer and use it in GitHub Desktop.
ionic proxy config
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;
}
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 {}
@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