www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Embedding run.dlang.io - allowed?

reply WebFreak001 <d.forum webfreak.org> writes:
Hi,

I would like to write a blog entry and include some small D 
snippets in it. I think it would be great if readers of my blog 
could experiment and edit the code right inside the website if 
they feel like it.

This would
1) help validate the code snippets are up-to-date
2) increase engagement with users
3) possibly increase users interested in D because they can 
quickly try it out

I saw the dlang tour has an API for doing the compilation, but is 
it allowed to use it for third party sites? For the few visitors 
I get anyway I would like to avoid hosting and maintaining what 
is basically "remote code execution as a service". To keep it 
secure I would obviously need to rent a new server for this or 
spin up cloud servers per API, so I would rather avoid that while 
I can.

I would also like to release the blog engine source code for this 
so anyone can make a blog with embedded D code (and possible 
future editor feature integrations) - so I wouldn't want an 
individual permission just for my blog!

Thanks!
WebFreak
May 07 2020
parent Petar Kirov [ZombineDev] <petar.p.kirov gmail.com> writes:
On Thursday, 7 May 2020 at 07:03:43 UTC, WebFreak001 wrote:
 Hi,

 I would like to write a blog entry and include some small D 
 snippets in it. I think it would be great if readers of my blog 
 could experiment and edit the code right inside the website if 
 they feel like it.

 This would
 1) help validate the code snippets are up-to-date
 2) increase engagement with users
 3) possibly increase users interested in D because they can 
 quickly try it out

 I saw the dlang tour has an API for doing the compilation, but 
 is it allowed to use it for third party sites? For the few 
 visitors I get anyway I would like to avoid hosting and 
 maintaining what is basically "remote code execution as a 
 service". To keep it secure I would obviously need to rent a 
 new server for this or spin up cloud servers per API, so I 
 would rather avoid that while I can.

 I would also like to release the blog engine source code for 
 this so anyone can make a blog with embedded D code (and 
 possible future editor feature integrations) - so I wouldn't 
 want an individual permission just for my blog!

 Thanks!
 WebFreak
Hi WebFreak, I think this is a great use case that we definitely want to support! In fact, all runnable examples on the dlang.org docs are powered by this API already ;) --- Unfortunately, lately, we (me and the other maintainers) have been quite busy and which is why we still haven't addressed some of the long-standing issues (fixing GitHub Gist support and URL shortening). Fortunately, other members of the community were able to help with tracking down the root cause and there's a PR open that would likely fix it: https://github.com/dlang-tour/core/pull/750, but it was blocked on pending PR for vibe-d: https://github.com/vibe-d/vibe.d/pull/2439) Edit: I see now that the dlang-tour/core PR is merged, but there are still some issues that need to be resolved, that I'll try to look into later this week. --- That said, we're very happy to accept contributions in this area (making it easier for users to embed runnable code snippets in their sites). Of course, if we notice that the service is being abused we will need to put some restrictions (request throttling, HTTP Referer whitelisting, requiring API tokens, etc.), but so far I think that we're good :) I suggest you have a look at the integration on dlang.org to have an idea what you need to do, in order to have the same functionality for your site: https://github.com/dlang/dlang.org/blob/master/js/run.js#L96 In the more distant future, one of the projects that I'd like to explore is completely overhauling the web UI to replace it with something IDE-like (e.g. hosting a web version VS Code), along the lines of https://codesandbox.io/. Of course, we should still have a very simple and bare-bones text editor, as I find it quite useful to test snippets on the go from my phone, and I think that many other users value simplicity. Cheers, Petar
May 07 2020