-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow the trace server URL to be configured
Fixes #79 The trace server URL can be set when starting the server, using the TRACE_SERVER_URL environment variable. So running TRACE_SERVER_URL=http://my.trace.server:port/tsp/api yarn start:browser will start the browser app with the trace server pointing to the URL variable. Signed-off-by: Geneviève Bastien <gbastien@versatic.net>
- Loading branch information
Showing
10 changed files
with
176 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
viewer-prototype/src/browser/trace-server-url-provider-frontend-impl.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { inject, injectable } from 'inversify'; | ||
import { TraceViewerEnvironment } from '../common/trace-viewer-environment'; | ||
import { TraceServerUrlProvider, TRACE_SERVER_DEFAULT_URL } from '../common/trace-server-url-provider'; | ||
import { FrontendApplicationContribution, FrontendApplication } from '@theia/core/lib/browser'; | ||
|
||
@injectable() | ||
export class TraceServerUrlProviderImpl implements TraceServerUrlProvider, FrontendApplicationContribution { | ||
|
||
protected _traceServerUrl: string; | ||
protected _listeners: ((url: string) => void)[]; | ||
|
||
constructor( | ||
@inject(TraceViewerEnvironment) protected readonly traceViewerEnvironment: TraceViewerEnvironment | ||
) { | ||
this._traceServerUrl = TRACE_SERVER_DEFAULT_URL; | ||
this._listeners = []; | ||
} | ||
|
||
async onStart(_app: FrontendApplication): Promise<void> { | ||
this._traceServerUrl = await this.traceViewerEnvironment.getTraceServerUrl(); | ||
this.updateListeners(); | ||
} | ||
|
||
async updateListeners(): Promise<void> { | ||
this._listeners.forEach(listener => listener(this._traceServerUrl)); | ||
} | ||
|
||
getTraceServerUrl(): string { | ||
return this._traceServerUrl; | ||
} | ||
|
||
/** | ||
* Add a listener for trace server url changes | ||
* @param listener The listener function to be called when the url is | ||
* changed | ||
*/ | ||
addTraceServerUrlChangedListener(listener: (url: string) => void): void { | ||
this._listeners.push(listener); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { injectable, inject } from 'inversify'; | ||
import { TraceServerUrlProvider } from '../common/trace-server-url-provider'; | ||
import { TspClient } from 'tsp-typescript-client/lib/protocol/tsp-client'; | ||
|
||
@injectable() | ||
export class TspClientProvider { | ||
|
||
private _tspClient: TspClient; | ||
private _listeners: ((tspClient: TspClient) => void)[]; | ||
|
||
constructor( | ||
@inject(TraceServerUrlProvider) private tspUrlProvider: TraceServerUrlProvider | ||
) { | ||
this._tspClient = new TspClient(this.tspUrlProvider.getTraceServerUrl()); | ||
this._listeners = []; | ||
tspUrlProvider.addTraceServerUrlChangedListener(url => { | ||
this._tspClient = new TspClient(url); | ||
this._listeners.forEach(listener => listener(this._tspClient)); | ||
}); | ||
} | ||
|
||
public getTspClient(): TspClient { | ||
return this._tspClient; | ||
} | ||
|
||
/** | ||
* Add a listener for trace server url changes | ||
* @param listener The listener function to be called when the url is | ||
* changed | ||
*/ | ||
addTspClientChangeListener(listener: (tspClient: TspClient) => void): void { | ||
this._listeners.push(listener); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export const TraceServerUrlProvider = Symbol('TraceServerUrlProvider'); | ||
export const TRACE_SERVER_DEFAULT_URL = 'http://localhost:8080/tsp/api'; | ||
export interface TraceServerUrlProvider { | ||
|
||
/** | ||
* Get the default trace server URL from the server | ||
*/ | ||
getTraceServerUrl(): Readonly<string>; | ||
|
||
/** | ||
* Add a listener for trace server url changes | ||
* @param listener The listener function to be called when the url is | ||
* changed | ||
*/ | ||
addTraceServerUrlChangedListener(listener: (url: string) => void): void; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { injectable, inject } from 'inversify'; | ||
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables'; | ||
import { TRACE_SERVER_DEFAULT_URL } from './trace-server-url-provider'; | ||
|
||
@injectable() | ||
export class TraceViewerEnvironment { | ||
|
||
constructor( | ||
@inject(EnvVariablesServer) protected readonly environments: EnvVariablesServer) { | ||
|
||
} | ||
|
||
protected _traceServerUrl: string | undefined; | ||
async getTraceServerUrl(): Promise<string> { | ||
if (!this._traceServerUrl) { | ||
const traceServerUrl = await this.environments.getValue('TRACE_SERVER_URL'); | ||
this._traceServerUrl = traceServerUrl ? this.parseUrl(traceServerUrl.value || TRACE_SERVER_DEFAULT_URL) : TRACE_SERVER_DEFAULT_URL; | ||
} | ||
return this._traceServerUrl; | ||
} | ||
|
||
private parseUrl(url: string): string { | ||
let lcUrl = url.toLowerCase(); | ||
// Add the http | ||
if (!lcUrl.startsWith('http')) { | ||
lcUrl = 'http://' + lcUrl; | ||
} | ||
// Make sure it does not end with a slash | ||
if (lcUrl.endsWith('/')) { | ||
lcUrl = lcUrl.substring(0, lcUrl.length - 1); | ||
} | ||
return lcUrl; | ||
} | ||
|
||
} |