import {Injectable} from '@angular/core';
import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from '@angular/common/http';
import {Observable} from 'rxjs/index';
import {ApiService} from "./api.service";
@Injectable({
	providedIn: 'root'
})
export class UrlInterceptorService implements HttpInterceptor {

	constructor(private api: ApiService) {
	}


	intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {

		const authToken: string = this.api.getAccessToken();

		const authReq = req.clone({
			headers: req.headers.set('Authorization', 'Bearer ' + authToken)
				.set('Application', 'WEB'),
			url: `${req.url}`
		});
		return next.handle(authReq);
	}
}
