Skip to content

Commit

Permalink
Merge pull request #71 from Bitspark/remove-localhost-in-prod
Browse files Browse the repository at this point in the history
Remove localhost in prod
  • Loading branch information
td5r committed Oct 23, 2018
2 parents 8372b3c + 7532938 commit aa21c25
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
21 changes: 9 additions & 12 deletions src/app/components/editor-debug-panel.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {OperatorDef, OperatorInstance} from '../classes/operator';
import * as deepEqual from 'deep-equal';
import {HttpClient} from '@angular/common/http';
import {TypeDefFormComponent} from './type-def-form.component';
import {ApiService} from '../services/api.service';

@Component({
selector: 'app-editor-debug-panel',
Expand Down Expand Up @@ -94,7 +95,7 @@ export class EditorDebugPanelComponent implements OnInit {
@Input()
public operatorName: string;

constructor(private ref: ChangeDetectorRef, private http: HttpClient) {
constructor(private ref: ChangeDetectorRef, private http: HttpClient, private api: ApiService) {
ref.detach();
}

Expand Down Expand Up @@ -158,19 +159,16 @@ export class EditorDebugPanelComponent implements OnInit {
}

public async sendInputValue(obj: any) {
await this.http.post(this.operatorEndpoint, JSON.stringify(obj)).toPromise();
await this.api.post(this.operatorEndpoint, {}, obj);
if (this.interval) {
setTimeout(() => this.fetchItems(), 150);
}
}

public stopOperator() {
this.http.request('delete', 'http://localhost:5149/run/', {
body: {
handle: this.runningHandle
}
}).toPromise()
.then(data => {
this.api.delete('/run/', {}, {
handle: this.runningHandle
}).then(data => {
if (data['status'] === 'success') {
this.running = false;
this.runningHandle = '';
Expand All @@ -190,7 +188,7 @@ export class EditorDebugPanelComponent implements OnInit {
}

private fetchItems() {
this.http.get(this.operatorEndpoint).toPromise()
this.api.get(this.operatorEndpoint)
.then(responses => {
this.debuggingReponses = responses as Array<any>;
this.ref.detectChanges();
Expand All @@ -208,13 +206,12 @@ export class EditorDebugPanelComponent implements OnInit {

const isStream = !this.httpInput() && !this.httpOutput();

this.http.post('http://localhost:5149/run/', {
this.api.post('/run/', {}, {
fqn: this.operatorName,
gens: this.debuggingGens,
props: this.debuggingProps,
stream: isStream
}).toPromise()
.then(data => {
}).then(data => {
if (data['status'] === 'success') {
this.debugState = 'debugging';
this.operatorEndpoint = data['url'];
Expand Down
13 changes: 10 additions & 3 deletions src/app/services/api.service.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {environment} from '../../environments/environment';

@Injectable()
export class ApiService {
private static host = 'http://localhost:5149';
private static host = environment.daemon;

constructor(private http: HttpClient) {
}

public async get(path: string, getParams?: any): Promise<Object> {
return await this.http.get(ApiService.host + path, {
return this.http.get(ApiService.host + path, {
params: getParams
}).toPromise();
}

public async post(path: string, getParams: any, postData: any): Promise<Object> {
return await this.http.post(ApiService.host + path, postData, {
return this.http.post(ApiService.host + path, postData, {
params: getParams,
responseType: 'json'
}).toPromise();
}

public async delete(path: string, getParams: any, postData: any): Promise<Object> {
return this.http.request('delete', ApiService.host + path, {
body: postData
}).toPromise();
}

public downloadUrl(fqop: string): string {
return `${ApiService.host}/share/export?fqop=${fqop}`;
}
Expand Down
3 changes: 2 additions & 1 deletion src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const environment = {
production: true
production: true,
daemon: ''
};
3 changes: 2 additions & 1 deletion src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// The list of file replacements can be found in `angular.json`.

export const environment = {
production: false
production: false,
daemon: 'http://localhost:5149'
};

/*
Expand Down

0 comments on commit aa21c25

Please sign in to comment.