| .. | .. |
|---|
| 23 | 23 | |
|---|
| 24 | 24 | // Set the default 'Content-Type' header |
|---|
| 25 | 25 | this.headers.set('Content-Type', 'application/json'); |
|---|
| 26 | | - let token = this.store.get<string>('token'); |
|---|
| 27 | | - if (token) { |
|---|
| 28 | | - this.headers.set('X-SECURIS-TOKEN', token); |
|---|
| 29 | | - |
|---|
| 30 | | - } |
|---|
| 31 | 26 | |
|---|
| 32 | 27 | } |
|---|
| 33 | 28 | } |
|---|
| .. | .. |
|---|
| 35 | 30 | @Injectable() |
|---|
| 36 | 31 | export class ApiXHRBackend extends XHRBackend { |
|---|
| 37 | 32 | |
|---|
| 38 | | - constructor(_browserXHR: BrowserXhr, _baseResponseOptions: ResponseOptions, _xsrfStrategy: XSRFStrategy) { |
|---|
| 33 | + constructor(_browserXHR: BrowserXhr, _baseResponseOptions: ResponseOptions, _xsrfStrategy: XSRFStrategy, private store: LocalStorageService) { |
|---|
| 39 | 34 | super(_browserXHR, _baseResponseOptions, _xsrfStrategy); |
|---|
| 40 | 35 | } |
|---|
| 41 | 36 | |
|---|
| 42 | 37 | createConnection(request: Request): XHRConnection { |
|---|
| 38 | + let token = this.store.get<string>('token'); |
|---|
| 39 | + if (token) { |
|---|
| 40 | + request.headers.set('X-SECURIS-TOKEN', token); |
|---|
| 41 | + } |
|---|
| 43 | 42 | if (!request.url.endsWith('.js') && !request.url.endsWith('.json') && !request.url.endsWith('.html') && !request.url.endsWith('.svg')){ |
|---|
| 44 | 43 | request.url = 'http://localhost:8080/securis/' + request.url; // prefix base url |
|---|
| 45 | 44 | } |
|---|