Support local servers on custom ports, Ref. #303

This commit is contained in:
ziajka
2019-02-26 16:16:54 +01:00
parent e0bae16093
commit 28c4c25d14
3 changed files with 24 additions and 15 deletions

View File

@ -56,6 +56,14 @@ exports.stopAllLocalServers = async () => {
function getServerArguments(server, overrides) { function getServerArguments(server, overrides) {
let serverArguments = []; let serverArguments = [];
if(server.host) {
serverArguments.push('--host');
serverArguments.push(server.host);
}
if(server.port) {
serverArguments.push('--port');
serverArguments.push(server.port);
}
return serverArguments; return serverArguments;
} }

View File

@ -16,11 +16,11 @@
<input matInput tabindex="1" formControlName="path" placeholder="Local server path" /> <input matInput tabindex="1" formControlName="path" placeholder="Local server path" />
</mat-form-field> </mat-form-field>
<mat-form-field *ngIf="serverForm.get('location').value === 'remote'"> <mat-form-field>
<input matInput tabindex="1" formControlName="host" placeholder="Host" /> <input matInput tabindex="1" formControlName="host" placeholder="Host" />
</mat-form-field> </mat-form-field>
<mat-form-field *ngIf="serverForm.get('location').value === 'remote'"> <mat-form-field>
<input matInput tabindex="1" formControlName="port" placeholder="Port" /> <input matInput tabindex="1" formControlName="port" placeholder="Port" />
</mat-form-field> </mat-form-field>

View File

@ -17,8 +17,8 @@ export class AddServerDialogComponent implements OnInit {
'name': new FormControl('', [ Validators.required ]), 'name': new FormControl('', [ Validators.required ]),
'location': new FormControl(''), 'location': new FormControl(''),
'path': new FormControl(''), 'path': new FormControl(''),
'host': new FormControl(''), 'host': new FormControl('', [ Validators.required ]),
'port': new FormControl(''), 'port': new FormControl('', [ Validators.required, Validators.min(1) ]),
'authorization': new FormControl('none'), 'authorization': new FormControl('none'),
'login': new FormControl(''), 'login': new FormControl(''),
'password': new FormControl('') 'password': new FormControl('')
@ -46,6 +46,14 @@ export class AddServerDialogComponent implements OnInit {
return 'remote'; return 'remote';
} }
getDefaultHost() {
return '127.0.0.1';
}
getDefaultPort() {
return 3080;
}
async getDefaultLocalServerPath() { async getDefaultLocalServerPath() {
if(this.electronService.isElectronApp) { if(this.electronService.isElectronApp) {
return await this.electronService.remote.require('./local-server.js').getLocalServerPath(); return await this.electronService.remote.require('./local-server.js').getLocalServerPath();
@ -60,32 +68,23 @@ export class AddServerDialogComponent implements OnInit {
this.serverForm.get('location').valueChanges.subscribe((location: string) => { this.serverForm.get('location').valueChanges.subscribe((location: string) => {
const pathControl = this.serverForm.get('path'); const pathControl = this.serverForm.get('path');
const portControl = this.serverForm.get('port');
const hostControl = this.serverForm.get('host');
if(location === 'local') { if(location === 'local') {
pathControl.setValue(defaultLocalServerPath); pathControl.setValue(defaultLocalServerPath);
pathControl.setValidators([Validators.required]); pathControl.setValidators([Validators.required]);
portControl.clearValidators();
hostControl.clearValidators();
} }
else { else {
pathControl.setValue(''); pathControl.setValue('');
pathControl.clearValidators(); pathControl.clearValidators();
portControl.setValidators([Validators.required, Validators.min(0)]);
hostControl.setValidators([Validators.required]);
} }
[pathControl, portControl, hostControl].forEach((control) => { [pathControl].forEach((control) => {
control.updateValueAndValidity({ control.updateValueAndValidity({
onlySelf: true onlySelf: true
}); });
}) })
}); });
this.serverForm.get('authorization').valueChanges.subscribe((authorization: string) => { this.serverForm.get('authorization').valueChanges.subscribe((authorization: string) => {
const loginControl = this.serverForm.get('login'); const loginControl = this.serverForm.get('login');
const passwordControl = this.serverForm.get('password'); const passwordControl = this.serverForm.get('password');
@ -107,6 +106,8 @@ export class AddServerDialogComponent implements OnInit {
}); });
this.serverForm.get('location').setValue(this.getDefaultLocation()); this.serverForm.get('location').setValue(this.getDefaultLocation());
this.serverForm.get('host').setValue(this.getDefaultHost());
this.serverForm.get('port').setValue(this.getDefaultPort());
this.serverForm.get('authorization').setValue('none'); this.serverForm.get('authorization').setValue('none');
} }