@exceptionless/fetchclient
Advanced tools
Comparing version 0.37.0 to 0.38.0
@@ -344,5 +344,21 @@ import { Counter } from "./Counter.js"; | ||
this.#provider.counter.increment(); | ||
let request = null; | ||
try { | ||
request = new Request(url, init); | ||
} | ||
catch { | ||
// try converting to absolute URL | ||
const origin = globalThis.location?.origin ?? "http://localhost"; | ||
if (!url.startsWith("http")) { | ||
if (url.startsWith("/")) { | ||
request = new Request(origin + url, init); | ||
} | ||
else { | ||
request = new Request(origin + url, init); | ||
} | ||
} | ||
} | ||
const context = { | ||
options, | ||
request: new Request(url, init), | ||
request: request, | ||
response: null, | ||
@@ -444,13 +460,16 @@ meta: {}, | ||
buildUrl(url, options) { | ||
if (url.startsWith("/")) { | ||
url = url.substring(1); | ||
let builtUrl = url; | ||
if (!builtUrl.startsWith("http") && this.options?.baseUrl) { | ||
if (this.options.baseUrl.endsWith("/") || builtUrl.startsWith("/")) { | ||
builtUrl = this.options.baseUrl + builtUrl; | ||
} | ||
else { | ||
builtUrl = this.options.baseUrl + "/" + builtUrl; | ||
} | ||
} | ||
if (!url.startsWith("http") && this.options?.baseUrl) { | ||
url = this.options.baseUrl + "/" + url; | ||
} | ||
const isAbsoluteUrl = url.startsWith("http"); | ||
const isAbsoluteUrl = builtUrl.startsWith("http"); | ||
const origin = isAbsoluteUrl | ||
? undefined | ||
: globalThis.location?.origin ?? undefined; | ||
const parsed = new URL(url, origin); | ||
: globalThis.location?.origin ?? "http://localhost"; | ||
const parsed = new URL(builtUrl, origin); | ||
if (options?.params) { | ||
@@ -462,5 +481,7 @@ for (const [key, value] of Object.entries(options?.params)) { | ||
} | ||
url = parsed.toString(); | ||
builtUrl = parsed.toString(); | ||
} | ||
const result = isAbsoluteUrl ? url : `${parsed.pathname}${parsed.search}`; | ||
const result = isAbsoluteUrl | ||
? builtUrl | ||
: `${parsed.pathname}${parsed.search}`; | ||
return result; | ||
@@ -467,0 +488,0 @@ } |
{ | ||
"name": "@exceptionless/fetchclient", | ||
"version": "0.37.0", | ||
"version": "0.38.0", | ||
"description": "A simple fetch client with middleware support for Deno and the browser.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -347,5 +347,21 @@ "use strict"; | ||
this.#provider.counter.increment(); | ||
let request = null; | ||
try { | ||
request = new Request(url, init); | ||
} | ||
catch { | ||
// try converting to absolute URL | ||
const origin = globalThis.location?.origin ?? "http://localhost"; | ||
if (!url.startsWith("http")) { | ||
if (url.startsWith("/")) { | ||
request = new Request(origin + url, init); | ||
} | ||
else { | ||
request = new Request(origin + url, init); | ||
} | ||
} | ||
} | ||
const context = { | ||
options, | ||
request: new Request(url, init), | ||
request: request, | ||
response: null, | ||
@@ -447,13 +463,16 @@ meta: {}, | ||
buildUrl(url, options) { | ||
if (url.startsWith("/")) { | ||
url = url.substring(1); | ||
let builtUrl = url; | ||
if (!builtUrl.startsWith("http") && this.options?.baseUrl) { | ||
if (this.options.baseUrl.endsWith("/") || builtUrl.startsWith("/")) { | ||
builtUrl = this.options.baseUrl + builtUrl; | ||
} | ||
else { | ||
builtUrl = this.options.baseUrl + "/" + builtUrl; | ||
} | ||
} | ||
if (!url.startsWith("http") && this.options?.baseUrl) { | ||
url = this.options.baseUrl + "/" + url; | ||
} | ||
const isAbsoluteUrl = url.startsWith("http"); | ||
const isAbsoluteUrl = builtUrl.startsWith("http"); | ||
const origin = isAbsoluteUrl | ||
? undefined | ||
: globalThis.location?.origin ?? undefined; | ||
const parsed = new URL(url, origin); | ||
: globalThis.location?.origin ?? "http://localhost"; | ||
const parsed = new URL(builtUrl, origin); | ||
if (options?.params) { | ||
@@ -465,5 +484,7 @@ for (const [key, value] of Object.entries(options?.params)) { | ||
} | ||
url = parsed.toString(); | ||
builtUrl = parsed.toString(); | ||
} | ||
const result = isAbsoluteUrl ? url : `${parsed.pathname}${parsed.search}`; | ||
const result = isAbsoluteUrl | ||
? builtUrl | ||
: `${parsed.pathname}${parsed.search}`; | ||
return result; | ||
@@ -470,0 +491,0 @@ } |
Sorry, the diff of this file is not supported yet
134681
2833