import { EnvironmentService } from './environment.service' ; import { Observable } from 'rxjs/Observable' ; import { Injectable } from '@angular/core' ; import { HttpEvent , HttpHandler , HttpInterceptor , HttpRequest } from '@angular/common/http' ; @ Injectable ( ) export class HttpConfigInterceptor implements HttpInterceptor { constructor ( private env ) { } intercept ( req , next ) { if ( req . url . includes ( 'http' ) ) return next . handle ( req ) ; if ( ! this . env . config . endpoints || ! this . env . config . endpoints . api ) throw new Error ( 'missing endpoint configuration value' ) ; if ( req . url . includes ( './' ) ) { if ( ! this . env . config . host ) throw new Error ( 'missing host configuration value' ) ; return next . handle ( req . clone ( { url : `${ this . env . config . host }/${ req . url . replace ( './' , '' ) }` } ) ) ; } return next . handle ( req . clone ( { url : `${ this . env . config . endpoints . api }/${ req . url }` } ) ) ; } }