Basic support of local server

This commit is contained in:
ziajka 2018-06-22 13:41:09 +02:00
parent d929cd4187
commit f1493800cd
4 changed files with 23 additions and 2 deletions

View File

@ -176,4 +176,17 @@ describe('HttpServer', () => {
expect(req.request.headers.get('Authorization')).toEqual('Basic bG9naW46cGFzc3dvcmQ=');
expect(req.request.headers.get('CustomHeader')).toEqual('value');
});
it('should make local call when ip and port is not defined', () => {
server.ip = null;
server.port = null;
service.get(server, '/test', {
headers: {
'CustomHeader': 'value'
}
}).subscribe();
const req = httpTestingController.expectOne('/v2/test');
});
});

View File

@ -112,7 +112,11 @@ export class HttpServer {
}
private getOptionsForServer<T extends HeadersOptions>(server: Server, url: string, options: T) {
url = `http://${server.ip}:${server.port}/v2${url}`;
if (server.ip && server.port) {
url = `http://${server.ip}:${server.port}/v2${url}`;
} else {
url = `/v2${url}`;
}
if (!options.headers) {
options.headers = {};

View File

@ -115,4 +115,5 @@ describe('ProjectService', () => {
const path = service.notificationsPath(server, "myproject");
expect(path).toEqual('ws://127.0.0.1:3080/v2/projects/myproject/notifications/ws')
}));
});

View File

@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
import {IndexedDbService} from "./indexed-db.service";
import {Server} from "../models/server";
import { Observable } from "rxjs/Observable";
@Injectable()
@ -23,7 +24,9 @@ export class ServerService {
public getLocalOrRemote(id: string) {
if (id === 'local') {
const server = new Server();
server.name = 'local';
return Observable.of(server);
}
return this.get(parseInt(id, 10));
}