diff --git a/src/app/components/servers/add-server-dialog/add-server-dialog.component.html b/src/app/components/servers/add-server-dialog/add-server-dialog.component.html index 5061ba51..1104fddf 100644 --- a/src/app/components/servers/add-server-dialog/add-server-dialog.component.html +++ b/src/app/components/servers/add-server-dialog/add-server-dialog.component.html @@ -28,6 +28,12 @@ + + + {{ protocol.name }} + + + {{ auth.name }} diff --git a/src/app/components/servers/add-server-dialog/add-server-dialog.component.ts b/src/app/components/servers/add-server-dialog/add-server-dialog.component.ts index d47ada14..ce40e905 100644 --- a/src/app/components/servers/add-server-dialog/add-server-dialog.component.ts +++ b/src/app/components/servers/add-server-dialog/add-server-dialog.component.ts @@ -13,6 +13,7 @@ import { ToasterService } from '../../../services/toaster.service'; }) export class AddServerDialogComponent implements OnInit { authorizations = [{ key: 'none', name: 'No authorization' }, { key: 'basic', name: 'Basic authorization' }]; + protocols = [{ key: 'http:', name: 'HTTP' }, { key: 'https:', name: 'HTTPS' }]; locations = []; serverForm = new FormGroup({ @@ -22,6 +23,7 @@ export class AddServerDialogComponent implements OnInit { 'ubridge_path': new FormControl(''), 'host': new FormControl('', [ Validators.required ]), 'port': new FormControl('', [ Validators.required, Validators.min(1) ]), + 'protocol': new FormControl('http:'), 'authorization': new FormControl('none'), 'login': new FormControl(''), 'password': new FormControl('') diff --git a/src/app/components/servers/server-discovery/server-discovery.component.ts b/src/app/components/servers/server-discovery/server-discovery.component.ts index c2cebc8e..c87a5088 100644 --- a/src/app/components/servers/server-discovery/server-discovery.component.ts +++ b/src/app/components/servers/server-discovery/server-discovery.component.ts @@ -3,13 +3,14 @@ import { Component, OnInit } from '@angular/core'; import { Observable } from 'rxjs/Rx'; import { map } from 'rxjs//operators'; -import { Server } from '../../../models/server'; +import { Server, ServerProtocol } from '../../../models/server'; import { VersionService } from '../../../services/version.service'; import { Version } from '../../../models/version'; import { forkJoin } from 'rxjs'; import { ServerService } from '../../../services/server.service'; import { ServerDatabase } from '../../../services/server.database'; import { from } from 'rxjs'; +import { ActivatedRoute } from '@angular/router'; @Component({ selector: 'app-server-discovery', @@ -29,7 +30,8 @@ export class ServerDiscoveryComponent implements OnInit { constructor( private versionService: VersionService, private serverService: ServerService, - private serverDatabase: ServerDatabase + private serverDatabase: ServerDatabase, + private route : ActivatedRoute ) {} ngOnInit() { @@ -94,6 +96,7 @@ export class ServerDiscoveryComponent implements OnInit { } server.location = 'remote'; + server.protocol = location.protocol as ServerProtocol; this.serverService.create(server).then((created: Server) => { this.serverDatabase.addServer(created); diff --git a/src/app/components/servers/servers.component.ts b/src/app/components/servers/servers.component.ts index 6f90c66d..8c613066 100644 --- a/src/app/components/servers/servers.component.ts +++ b/src/app/components/servers/servers.component.ts @@ -4,8 +4,8 @@ import { MatBottomSheet } from '@angular/material/bottom-sheet'; import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; import { Observable, merge, Subscription } from 'rxjs'; import { map } from 'rxjs/operators'; -import { Router } from '@angular/router'; -import { Server } from '../../models/server'; +import { ActivatedRoute, Router } from '@angular/router'; +import { Server, ServerProtocol } from '../../models/server'; import { ServerService } from '../../services/server.service'; import { ServerDatabase } from '../../services/server.database'; import { AddServerDialogComponent } from './add-server-dialog/add-server-dialog.component'; @@ -35,6 +35,7 @@ export class ServersComponent implements OnInit, OnDestroy { private electronService: ElectronService, private childProcessService: ChildProcessService, private bottomSheet: MatBottomSheet, + private route : ActivatedRoute ) {} getServers() { diff --git a/src/app/models/server.ts b/src/app/models/server.ts index 271991a5..d8a546d3 100644 --- a/src/app/models/server.ts +++ b/src/app/models/server.ts @@ -1,6 +1,7 @@ export type ServerAuthorization = 'basic' | 'none'; export type ServerLocation = 'local' | 'remote' | 'bundled'; export type ServerStatus = 'stopped' | 'starting' | 'running'; +export type ServerProtocol = 'http' | 'https' export class Server { id: number; @@ -14,4 +15,5 @@ export class Server { login: string; password: string; status: ServerStatus; + protocol: ServerProtocol; } diff --git a/src/app/services/http-server.service.ts b/src/app/services/http-server.service.ts index 2b59cb87..56611156 100644 --- a/src/app/services/http-server.service.ts +++ b/src/app/services/http-server.service.ts @@ -4,7 +4,7 @@ import { HttpHeaders, HttpClient, HttpParams, HttpErrorResponse } from '@angular import { Observable, throwError } from 'rxjs'; import { catchError } from 'rxjs/operators'; -import { Server } from '../models/server'; +import { Server, ServerProtocol } from '../models/server'; /* tslint:disable:interface-over-type-literal */ export type JsonOptions = { @@ -176,12 +176,14 @@ export class HttpServer { } private getOptionsForServer(server: Server, url: string, options: T) { + console.log('Server ', server.protocol); + console.log('Location ', location.protocol); + if (server.host && server.port) { - if (server.authorization === 'basic') { - url = `https://${server.host}:${server.port}/v2${url}`; - } else { - url = `http://${server.host}:${server.port}/v2${url}`; + if (!server.protocol) { + server.protocol = location.protocol as ServerProtocol; } + url = `${server.protocol}//${server.host}:${server.port}/v2${url}`; } else { url = `/v2${url}`; } diff --git a/src/app/services/server.service.ts b/src/app/services/server.service.ts index d677c178..a89bafef 100644 --- a/src/app/services/server.service.ts +++ b/src/app/services/server.service.ts @@ -1,6 +1,6 @@ import { Injectable, EventEmitter } from '@angular/core'; import { IndexedDbService } from './indexed-db.service'; -import { Server } from '../models/server'; +import { Server, ServerProtocol } from '../models/server'; import { Observable, Subject } from 'rxjs'; import { HttpServer } from './http-server.service'; @@ -138,7 +138,7 @@ export class ServerService { } public getServerUrl(server: Server) { - return `http://${server.host}:${server.port}/`; + return `${server.protocol}//${server.host}:${server.port}/`; } public checkServerVersion(server: Server): Observable { @@ -152,6 +152,7 @@ export class ServerService { if (local) { local.host = host; local.port = port; + local.protocol = location.protocol as ServerProtocol; this.update(local).then(updated => { resolve(updated); }, reject); @@ -161,6 +162,7 @@ export class ServerService { server.host = host; server.port = port; server.location = 'bundled'; + server.protocol = location.protocol as ServerProtocol; this.create(server).then(created => { resolve(created); }, reject);