microsoft / maker.js

📐⚙ 2D vector line drawing and shape modeling for CNC and laser cutters.
http://maker.js.org
Apache License 2.0
1.77k stars 273 forks source link

Link to external js file #220

Closed 3kmch closed 7 years ago

3kmch commented 7 years ago

Is it already possible to add an external file to the playground? This way I don't have to set up my own Maker.js platform. See also at OpenJSCAD: http://openjscad.org/#http://www.thingiverse.com/download:164128 (STL) or http://openjscad.org/#http://openjscad.org/examples/slices/tor.jscad

danmarshall commented 7 years ago

It's definitely possible, but it also presents a security issue because the js files would execute. If someone created a link to a malicious script, it could eventually blacklist the Maker.js site.

Generally my solution to this was to accept PRs and host the js here on the site. This would mean you would be sharing your code publicly.

If folks don't want their code to be public, we could have something like: Don't immediately execute external scripts, and show an "I agree" button that the user accepts the risk.

3kmch commented 7 years ago

Thank you for your reply. :)

Sharing it on your site is a good solution. But I assume this would be a solution that depends on your spare time, so perhaps not an instant one. ;-)

So having the opportunity to add the js file directly would be awesome and having an [I agree] button sounds reasonable.

danmarshall commented 7 years ago

Another option to be aware of, is that it is pretty easy to host your own copy of the site, here on GitHub:

  1. Click the "Fork" button in the top right corner of the page. This will create your own copy of this repo.
  2. Visit http://YOURUSERNAME.github.io/maker.js/demos/
danmarshall commented 7 years ago

Ok, you can now specify an external script. You will see a warning screen, and the code will not auto-execute, you must click the Run button.

Example: http://microsoft.github.io/maker.js/playground/?script=https://gist.githubusercontent.com/danmarshall/8eb60f82ca765f477f0bc3a73966317a/raw/ebfeb4fa2db63726f6e9d30580f1df9f83b54ca1/heart.js

3kmch commented 7 years ago

Cool, that was quick. :)

I tried to refer to http://microsoft.github.io/maker.js/playground/?script=http://3km.ch/makerjs/sleeve.js but got an error (message in browser):

Load module failure : Could not load script "http://3km.ch/makerjs/sleeve.js". Possibly a network error, or the file does not exist.

Message in console:

XMLHttpRequest cannot load http://3km.ch/makerjs/sleeve.js. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://microsoft.github.io' is therefore not allowed access.

Do you just allow files from github?

danmarshall commented 7 years ago

Actually it's the 3km.ch server which is not allowing the resource. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

In my example I used a GitHub Gist which was convenient, you may want to try it: https://gist.github.com/

3kmch commented 7 years ago

OK, I git it; did it the GitHub way:

http://microsoft.github.io/maker.js/playground/?script=https://raw.githubusercontent.com/3kmch/makerjs/master/sleeve.js

It just works. Thank you very much. :)

danmarshall commented 7 years ago

Sure :) Also have you tried running it on your local machine?

3kmch commented 7 years ago

No, not yet.