How do I set up a sandboxed webserver?

So browsers are very security conscious these days. They won’t allow you to do an AJAX call to get a file off your file system since a hacker could access any data on your system. So to exercise APIcall to access a file on disc we need to use a webserver. To spin up a webserver, navigate to the folder you would like to be able to access and run:

python3 -m http.server --cgi 8080

This works under Mac OS X. Since it depends on your environment and having developer tools installed you might need to install the xcode command line tools.

The only thing that you will need to do is change the APIcall to use a “GET” method since this webserver has some limitations.

In this example you can try using the on loaded event to fire off an APIcall. The file “example.json” is a file that is located in the folder that the webserver is running.

READYevent(function(){ var Path = "example.json"; APIcall(Path,{},APIsuccess); }); function APIsuccess(Data){ console.log("Successful API call", Data); }

For more reading about starting a simple webserver