Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/lib/http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,26 @@ describe('HttpClient — Dynatrace authentication', () => {
await client.dynatracePlatform('/platform/storage/query/v1/query:execute');
expect(authorization).toBe('Bearer platform-token');
});

it('preserves /e/<environment-id> path segment for Dynatrace Managed base URLs', async () => {
const capturedUrls: string[] = [];
vi.stubGlobal('fetch', async (url: string) => {
capturedUrls.push(url);
return new Response('{"entities":[],"totalCount":0}', { status: 200 });
});
const client = new HttpClient(baseConfig({
dynatrace: {
baseUrl: 'https://apm.pncint.net/e/ccd497ef-cb0f-4294-9044-1b6faead0768',
apiToken: 'tok',
platformUrl: undefined,
platformToken: undefined
}
}));
await client.dynatrace('/api/v2/entities');
expect(capturedUrls[0]).toBe(
'https://apm.pncint.net/e/ccd497ef-cb0f-4294-9044-1b6faead0768/api/v2/entities'
);
});
});

describe('HttpClient — --debug mode', () => {
Expand Down
9 changes: 8 additions & 1 deletion src/lib/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ function redactHeaders(headers: RequestInit['headers']): Record<string, string>
}

function buildUrl(base: string, path: string, params?: Record<string, string | number | boolean | undefined>): string {
const url = new URL(path, base.endsWith('/') ? base : base + '/');
const normalizedBase = base.endsWith('/') ? base : base + '/';
// Strip a leading '/' so that new URL(path, base) resolves relative to base's full
// path rather than the origin. Per the WHATWG URL spec, an absolute-path reference
// (starting with '/') resolves against the origin and discards any path already
// present in base — which silently drops path segments like '/e/<environment-id>'
// from Dynatrace Managed or Artifactory-with-context-root base URLs.
const normalizedPath = path.startsWith('/') ? path.slice(1) : path;
const url = new URL(normalizedPath, normalizedBase);
if (params) {
for (const [key, val] of Object.entries(params)) {
if (val !== undefined) {
Expand Down
Loading