Skip to content

Conversation

shehab299
Copy link

The previous version of Faustwasm only supported using local files as imports. The goal was to extend its capabilities to support both HTTP/HTTPS and pkgUrl imports.

This was achieved by transitioning from using the libcurl library for downloading files to using XMLHttpRequest in browser environments. Since XMLHttpRequest isn't defined in Node.js, an external library, "xmlhttprequest," was used to ensure compatibility.

if (
	typeof window !== 'undefined' && 
	typeof window.XMLHttpRequest !== 'undefined'
) {
	var xhr = new window.XMLHttpRequest();
	xhr.open('GET', UTF8ToString(url), false);
	xhr.send(null);

	if (xhr.status >= 200 && xhr.status < 300) {
		dsp_code = xhr.responseText;   
	} 
} 
else if (
	typeof process != 'undefined'  && 
	process.versions != null && process.versions.node != null
) {
	var XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
	var xhr = new XMLHttpRequest();
	xhr.open('GET', UTF8ToString(url), false);
	xhr.send(null); 
	if (xhr.status >= 200 && xhr.status < 300) {
		dsp_code = xhr.responseText;
	} 
}

Note: When bundling for the web, you might encounter errors indicating that HTTP library doesn't exist. This is normal because the library is only required if the environment is Node.js, so it isn't an actual error.

As a result, Faustwasm now allows dependencies on packages from the registry and libraries served via HTTP and HTTPS protocols.

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

Successfully merging this pull request may close these issues.

1 participant