fix(sw): pass server as relative path

This commit is contained in:
Simon Knott 2024-11-19 08:37:55 +00:00
parent dc91bab6cc
commit f7925629af
4 changed files with 10 additions and 10 deletions

View file

@ -125,7 +125,7 @@ export async function installRootRedirect(server: HttpServer, traceUrls: string[
for (const reporter of options.reporter || []) for (const reporter of options.reporter || [])
params.append('reporter', reporter); params.append('reporter', reporter);
params.set('server', server.urlPrefix('precise')); params.set('server', '..');
const urlPath = `./trace/${options.webApp || 'index.html'}?${params.toString()}`; const urlPath = `./trace/${options.webApp || 'index.html'}?${params.toString()}`;
server.routePath('/', (_, response) => { server.routePath('/', (_, response) => {

View file

@ -43,12 +43,9 @@ async function loadTrace(traceUrl: string, traceFileName: string | null, client:
const clientId = client?.id ?? ''; const clientId = client?.id ?? '';
let data = clientIdToTraceUrls.get(clientId); let data = clientIdToTraceUrls.get(clientId);
if (!data) { if (!data) {
let traceViewerServerBaseUrl = self.registration.scope; let traceViewerServerBaseUrl = new URL(client?.url ?? self.registration.scope);
if (client?.url) { if (traceViewerServerBaseUrl.searchParams.has('server'))
const clientUrl = new URL(client.url); traceViewerServerBaseUrl = new URL(traceViewerServerBaseUrl.searchParams.get('server')!, traceViewerServerBaseUrl)
if (clientUrl.searchParams.has('server'))
traceViewerServerBaseUrl = clientUrl.searchParams.get('server')!;
}
data = { limit, traceUrls: new Set(), traceViewerServer: new TraceViewerServer(traceViewerServerBaseUrl) }; data = { limit, traceUrls: new Set(), traceViewerServer: new TraceViewerServer(traceViewerServerBaseUrl) };
clientIdToTraceUrls.set(clientId, data); clientIdToTraceUrls.set(clientId, data);

View file

@ -146,7 +146,7 @@ function formatUrl(trace: string, server: TraceViewerServer) {
} }
export class TraceViewerServer { export class TraceViewerServer {
constructor(private readonly baseUrl: string) {} constructor(private readonly baseUrl: URL) {}
getFileURL(path: string): URL { getFileURL(path: string): URL {
const url = new URL('trace/file', this.baseUrl); const url = new URL('trace/file', this.baseUrl);

View file

@ -48,8 +48,11 @@ const xtermDataSource: XtermDataSource = {
const searchParams = new URLSearchParams(window.location.search); const searchParams = new URLSearchParams(window.location.search);
const guid = searchParams.get('ws'); const guid = searchParams.get('ws');
const wsURL = new URL(`../${guid}`, window.location.toString()); let testServerBaseUrl = new URL(window.location.href);
wsURL.protocol = (window.location.protocol === 'https:' ? 'wss:' : 'ws:'); if (testServerBaseUrl.searchParams.has('server'))
testServerBaseUrl = new URL(testServerBaseUrl.searchParams.get('server')!, testServerBaseUrl);
const wsURL = new URL(`../${guid}`, testServerBaseUrl);
wsURL.protocol = (wsURL.protocol === 'https:' ? 'wss:' : 'ws:');
const queryParams = { const queryParams = {
args: searchParams.getAll('arg'), args: searchParams.getAll('arg'),
grep: searchParams.get('grep') || undefined, grep: searchParams.get('grep') || undefined,