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

Master dev (non-built pr) #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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