From 2cbf1474c3402ff196a6a5a201e2c625cce733cc Mon Sep 17 00:00:00 2001 From: softsimon Date: Mon, 23 Nov 2020 18:22:21 +0700 Subject: [PATCH] New frontend config for webserver url to fix static asset httpGet. Removed "absolute" from config names. --- frontend/mempool-frontend-config.sample.json | 7 ++++--- frontend/server.ts | 4 ++-- frontend/src/app/services/api.service.ts | 4 ++-- frontend/src/app/services/assets.service.ts | 13 ++++++++++--- frontend/src/app/services/electrs-api.service.ts | 2 +- frontend/src/app/services/state.service.ts | 6 ++++-- 6 files changed, 23 insertions(+), 13 deletions(-) diff --git a/frontend/mempool-frontend-config.sample.json b/frontend/mempool-frontend-config.sample.json index 44e3ee945..2b436b875 100644 --- a/frontend/mempool-frontend-config.sample.json +++ b/frontend/mempool-frontend-config.sample.json @@ -6,7 +6,8 @@ "ELECTRS_ITEMS_PER_PAGE": 25, "KEEP_BLOCKS_AMOUNT": 8, "SPONSORS_ENABLED": false, - "BACKEND_ABSOLUTE_URL": "http://localhost:8999", - "ELECTRS_ABSOLUTE_URL": "http://localhost:4200", - "ELECTRS_ABSOLUTE_URL_SERVER": "http://localhost:50001" + "BACKEND_URL": "http://127.0.0.1:8999", + "ELECTRS_URL": "http://127.0.0.1:4200", + "ELECTRS_URL_SERVER": "http://127.0.0.1:50001", + "STATIC_WEBSERVER_URL": "http://127.0.0.1:4200" } \ No newline at end of file diff --git a/frontend/server.ts b/frontend/server.ts index 7945615c4..54a8d8a71 100644 --- a/frontend/server.ts +++ b/frontend/server.ts @@ -68,14 +68,14 @@ export function app(): express.Express { server.get('/api/v1/**', createProxyMiddleware({ // @ts-ignore - target: win.__env.BACKEND_ABSOLUTE_URL, + target: win.__env.BACKEND_URL, changeOrigin: true, }, )); server.get('/api/**', createProxyMiddleware({ // @ts-ignore - target: win.__env.ELECTRS_ABSOLUTE_URL_SERVER, + target: win.__env.ELECTRS_URL_SERVER, changeOrigin: true, pathRewrite: {'^/api' : '/'} }, diff --git a/frontend/src/app/services/api.service.ts b/frontend/src/app/services/api.service.ts index 0e62ce721..a7d6addf2 100644 --- a/frontend/src/app/services/api.service.ts +++ b/frontend/src/app/services/api.service.ts @@ -23,13 +23,13 @@ export class ApiService { } this.apiBaseUrl = API_BASE_URL.replace('{network}', network ? '/' + network : ''); if (!stateService.isBrowser) { - this.apiBaseUrl = this.stateService.env.BACKEND_ABSOLUTE_URL + this.apiBaseUrl; + this.apiBaseUrl = this.stateService.env.BACKEND_URL + this.apiBaseUrl; } }); this.apiBaseUrl = API_BASE_URL.replace('{network}', ''); if (!stateService.isBrowser) { - this.apiBaseUrl = this.stateService.env.BACKEND_ABSOLUTE_URL + this.apiBaseUrl; + this.apiBaseUrl = this.stateService.env.BACKEND_URL + this.apiBaseUrl; } } diff --git a/frontend/src/app/services/assets.service.ts b/frontend/src/app/services/assets.service.ts index 2adf57211..bc83b0bce 100644 --- a/frontend/src/app/services/assets.service.ts +++ b/frontend/src/app/services/assets.service.ts @@ -2,6 +2,7 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs'; import { shareReplay } from 'rxjs/operators'; +import { StateService } from './state.service'; @Injectable({ providedIn: 'root' @@ -13,9 +14,15 @@ export class AssetsService { constructor( private httpClient: HttpClient, + private stateService: StateService, ) { - this.getAssetsJson$ = this.httpClient.get('/resources/assets.json').pipe(shareReplay()); - this.getAssetsMinimalJson$ = this.httpClient.get('/resources/assets.minimal.json').pipe(shareReplay()); - this.getMiningPools$ = this.httpClient.get('/resources/pools.json').pipe(shareReplay()); + let baseApiUrl = ''; + if (!this.stateService.isBrowser) { + baseApiUrl = this.stateService.env.STATIC_WEBSERVER_URL; + } + + this.getAssetsJson$ = this.httpClient.get(baseApiUrl + '/resources/assets.json').pipe(shareReplay()); + this.getAssetsMinimalJson$ = this.httpClient.get(baseApiUrl + '/resources/assets.minimal.json').pipe(shareReplay()); + this.getMiningPools$ = this.httpClient.get(baseApiUrl + '/resources/pools.json').pipe(shareReplay()); } } diff --git a/frontend/src/app/services/electrs-api.service.ts b/frontend/src/app/services/electrs-api.service.ts index e67a3800e..167cb6d44 100644 --- a/frontend/src/app/services/electrs-api.service.ts +++ b/frontend/src/app/services/electrs-api.service.ts @@ -17,7 +17,7 @@ export class ElectrsApiService { private stateService: StateService, ) { if (!stateService.isBrowser) { - API_BASE_URL = this.stateService.env.ELECTRS_ABSOLUTE_URL; + API_BASE_URL = this.stateService.env.ELECTRS_URL + '/api'; } this.apiBaseUrl = API_BASE_URL.replace('{network}', ''); this.stateService.networkChanged$.subscribe((network) => { diff --git a/frontend/src/app/services/state.service.ts b/frontend/src/app/services/state.service.ts index 495f58909..97c226602 100644 --- a/frontend/src/app/services/state.service.ts +++ b/frontend/src/app/services/state.service.ts @@ -21,8 +21,10 @@ export interface Env { SPONSORS_ENABLED: boolean; ELECTRS_ITEMS_PER_PAGE: number; KEEP_BLOCKS_AMOUNT: number; - BACKEND_ABSOLUTE_URL?: string; - ELECTRS_ABSOLUTE_URL?: string; + BACKEND_URL?: string; + ELECTRS_URL?: string; + ELECTRS_URL_SERVER?: string; + STATIC_WEBSERVER_URL?: string; } const defaultEnv: Env = {