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('Authorization')).toEqual('Basic bG9naW46cGFzc3dvcmQ=');
expect(req.request.headers.get('CustomHeader')).toEqual('value'); 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) { private getOptionsForServer<T extends HeadersOptions>(server: Server, url: string, options: T) {
if (server.ip && server.port) {
url = `http://${server.ip}:${server.port}/v2${url}`; url = `http://${server.ip}:${server.port}/v2${url}`;
} else {
url = `/v2${url}`;
}
if (!options.headers) { if (!options.headers) {
options.headers = {}; options.headers = {};

View File

@ -115,4 +115,5 @@ describe('ProjectService', () => {
const path = service.notificationsPath(server, "myproject"); const path = service.notificationsPath(server, "myproject");
expect(path).toEqual('ws://127.0.0.1:3080/v2/projects/myproject/notifications/ws') 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 {IndexedDbService} from "./indexed-db.service";
import {Server} from "../models/server"; import {Server} from "../models/server";
import { Observable } from "rxjs/Observable";
@Injectable() @Injectable()
@ -23,7 +24,9 @@ export class ServerService {
public getLocalOrRemote(id: string) { public getLocalOrRemote(id: string) {
if (id === 'local') { if (id === 'local') {
const server = new Server();
server.name = 'local';
return Observable.of(server);
} }
return this.get(parseInt(id, 10)); return this.get(parseInt(id, 10));
} }