fetch-mock icon indicating copy to clipboard operation
fetch-mock copied to clipboard

fallbackToNetwork does not work with relative URLs

Open Knagis opened this issue 1 year ago • 1 comments

when fetch-mock is running with fallbackToNetwork = true, any relative URLs are always prepended with /

fetch("image.png") results in network request to "/image.png", when the index.html is not hosted on the root of the domain.

This is because of normalizeURL rebases the URL not to the current pathname:

	} else {
		const u = new URL(url, 'http://dummy');
		return u.pathname + u.search;
	}

Knagis avatar Apr 16 '24 08:04 Knagis

One potential workaround for this could be

new URL(url, typeof location === "undefined" ? 'http://dummy' : location.href);

Knagis avatar Apr 16 '24 09:04 Knagis

I now have a 'fix' for this being rolled out in @fetch-mock/core https://github.com/wheresrhys/fetch-mock/pull/805

wheresrhys avatar Aug 13 '24 21:08 wheresrhys