Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fallbackToNetwork does not work with relative URLs #669

Open
Knagis opened this issue Apr 16, 2024 · 1 comment
Open

fallbackToNetwork does not work with relative URLs #669

Knagis opened this issue Apr 16, 2024 · 1 comment

Comments

@Knagis
Copy link

Knagis commented Apr 16, 2024

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
Copy link
Author

Knagis commented Apr 16, 2024

One potential workaround for this could be

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant