Skip to content

Commit

Permalink
fix(ui): Removed hardcoded socket connection url
Browse files Browse the repository at this point in the history
Reuse url variables across klingon-ui through environment

Fixed angular-klingon#58
  • Loading branch information
sumitparakh authored and manekinekko committed Oct 1, 2018
1 parent 897d34f commit 2130a3d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CliService } from './../../cli/cli.service';
import { Injectable } from '@angular/core';
import { environment } from '../../../environments/environment';

export interface Terminal {
_initialized: boolean;
Expand Down Expand Up @@ -52,14 +53,14 @@ export class TerminalService {
}
const cols = size.cols;
const rows = size.rows;
const url = `http://localhost:3000/terminals/${
const url = environment.scheme + `://` + environment.host + `:` + environment.port + `/terminals/${
this.pid
}/size?cols=${cols}&rows=${rows}`;

fetch(url, { method: 'POST' });
});

this.socketURL = `ws://localhost:3000/terminals`;
this.socketURL = `ws://` + environment.host + `:` + environment.port + `/terminals`;

this.term.open(terminalContainer, false);
this.term.fit();
Expand All @@ -69,7 +70,7 @@ export class TerminalService {
const rows = 50;

const res = await fetch(
`http://localhost:3000/terminals?cols=${cols}&rows=${rows}`,
environment.scheme + `://` + environment.host + `:` + environment.port + `/terminals?cols=${cols}&rows=${rows}`,
{
method: 'POST'
}
Expand Down
3 changes: 2 additions & 1 deletion packages/klingon-ui/src/app/cli/cli.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Subject } from 'rxjs';
import { environment } from '../../environments/environment';

export interface CommandResult {
stderr: string;
Expand All @@ -15,7 +16,7 @@ export class CliService {

constructor() {
this.response$ = new Subject();
this.ws = new WebSocket(`ws://localhost:3000/cli`);
this.ws = new WebSocket(`ws://` + environment.host + `:` + environment.port + `/cli`);
this.ws.onopen = e => {
this.isConnectionOn = true;
};
Expand Down
5 changes: 4 additions & 1 deletion packages/klingon-ui/src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export const environment = {
production: true
production: true,
scheme: 'http',
host: 'localhost',
port: 3000
};
5 changes: 4 additions & 1 deletion packages/klingon-ui/src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
// The list of which env maps to which file can be found in `.angular-cli.json`.

export const environment = {
production: false
production: false,
scheme: 'http',
host: 'localhost',
port: 3000
};

0 comments on commit 2130a3d

Please sign in to comment.