From f1493800cd16dd2a14a72ddf6d06c0a010b4ee31 Mon Sep 17 00:00:00 2001 From: ziajka Date: Fri, 22 Jun 2018 13:41:09 +0200 Subject: [PATCH] Basic support of local server --- src/app/shared/services/http-server.service.spec.ts | 13 +++++++++++++ src/app/shared/services/http-server.service.ts | 6 +++++- src/app/shared/services/project.service.spec.ts | 1 + src/app/shared/services/server.service.ts | 5 ++++- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/app/shared/services/http-server.service.spec.ts b/src/app/shared/services/http-server.service.spec.ts index 4ce363fc..0034dd70 100644 --- a/src/app/shared/services/http-server.service.spec.ts +++ b/src/app/shared/services/http-server.service.spec.ts @@ -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'); + }); }); diff --git a/src/app/shared/services/http-server.service.ts b/src/app/shared/services/http-server.service.ts index d9aee35d..56a22919 100644 --- a/src/app/shared/services/http-server.service.ts +++ b/src/app/shared/services/http-server.service.ts @@ -112,7 +112,11 @@ export class HttpServer { } private getOptionsForServer(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 = {}; diff --git a/src/app/shared/services/project.service.spec.ts b/src/app/shared/services/project.service.spec.ts index 32ad72c5..f9ba5236 100644 --- a/src/app/shared/services/project.service.spec.ts +++ b/src/app/shared/services/project.service.spec.ts @@ -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') })); + }); diff --git a/src/app/shared/services/server.service.ts b/src/app/shared/services/server.service.ts index 0f4c792b..36d3313d 100644 --- a/src/app/shared/services/server.service.ts +++ b/src/app/shared/services/server.service.ts @@ -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)); }