major refactoring
added universal added api
This commit is contained in:
parent
2bea201bb3
commit
a4542f7abd
52 changed files with 2851 additions and 313 deletions
16
src/app/_service/api.service.spec.ts
Normal file
16
src/app/_service/api.service.spec.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ApiService } from './api.service';
|
||||
|
||||
describe('ApiService', () => {
|
||||
let service: ApiService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(ApiService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
25
src/app/_service/api.service.ts
Normal file
25
src/app/_service/api.service.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import {Inject, Injectable, PLATFORM_ID} from '@angular/core';
|
||||
import {Observable} from "rxjs";
|
||||
import {CurrentStatus, MetaInfo} from "../_data/data";
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
import {environment} from "../../environments/environment";
|
||||
import {isPlatformBrowser} from "@angular/common";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ApiService {
|
||||
private readonly api;
|
||||
|
||||
constructor(private http: HttpClient, @Inject(PLATFORM_ID) platformId: Object) {
|
||||
this.api = isPlatformBrowser(platformId) ? '/api' : environment.serverUrl + '/api';
|
||||
}
|
||||
|
||||
public getServiceStates(): Observable<CurrentStatus> {
|
||||
return this.http.get<CurrentStatus>(this.api+ '/status');
|
||||
}
|
||||
|
||||
public getMetaInfo(): Observable<MetaInfo> {
|
||||
return this.http.get<MetaInfo>(this.api+ '/info');
|
||||
}
|
||||
}
|
Reference in a new issue