Created
March 9, 2018 11:13
-
-
Save denisoster/3dd2dddec0cb422f2c9edea26773cf5e to your computer and use it in GitHub Desktop.
base.url Angular 5
This file contains hidden or 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 { Injectable } from '@angular/core'; | |
import {HttpEvent, HttpInterceptor, HttpHandler, HttpRequest} from '@angular/common/http'; | |
import {Observable} from 'rxjs/Observable'; | |
import { environment } from "../../../../environments/environment"; | |
@Injectable() | |
export class APIHttpInterceptor implements HttpInterceptor { | |
private baseUrl: string = environment.API_BASE_URL; | |
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { | |
const apiReq = req.clone({ url: `${this.baseUrl}/${req.url}` }); | |
return next.handle(apiReq); | |
} | |
} |
This file contains hidden or 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 {BrowserModule} from '@angular/platform-browser'; | |
import {NgModule} from '@angular/core'; | |
import {AppRoutingModule} from './app-routing.module'; | |
import {AppComponent} from './app.component'; | |
import {HttpClientModule, HTTP_INTERCEPTORS} from '@angular/common/http'; | |
import {APIHttpInterceptor} from "./system/shared/interactors/APIhttp.interactor"; | |
@NgModule({ | |
declarations: [ | |
AppComponent | |
], | |
imports: [ | |
BrowserModule, | |
AppRoutingModule, | |
HttpClientModule | |
], | |
providers: [{ | |
provide: HTTP_INTERCEPTORS, | |
useClass: APIHttpInterceptor, | |
multi: true | |
}], | |
bootstrap: [AppComponent] | |
}) | |
export class AppModule { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment