reveal-sampler icon indicating copy to clipboard operation
reveal-sampler copied to clipboard

Allow to configure a proxy to fetch the snippets

Open ThomasWeinert opened this issue 6 years ago • 4 comments

I am using sampler with PHP snippets, but my webserver (local inside the IDE) support PHP. So I only get empty responses. :-)

A small proxy script allows to fetch the source of the PHP files.

This branch includes the changes for the indentation behavior. Both read options, so they might conflict otherwise.

ThomasWeinert avatar Nov 24 '18 15:11 ThomasWeinert

I'm not sure I understand the purpose of this feature and what it's enabling that the current thing doesn't. Could you please try explaining again?

ldionne avatar Dec 03 '18 18:12 ldionne

It is a specific use case.

The snippets in my presentation are PHP unit tests. They are tasks for the attendees to solve (using a wireless keyboard that goes around).

The IDE is configured to treat this as a web project and knows/has a PHP executable. If I now start the IDE built-in webserver the plugin is not able to get the source code directly. The webserver will execute the PHP (only class definitions so nothing happens) and return an empty response. Here is not an configuration in the IDE to disable the PHP executable just for the webserver. Renaming the files or disabling PHP would mean loosing IDE features.

Here are two solutions originally. Opening the index.html from the file system would avoid the PHP execution, but add other restrictions. Browsers behave differently in this case. The other option would be to change all the URLs in the data-sample attributes. It would make them a lot harder to read and the presentation would not work on a webserver without PHP support.

The configuration option can depend on the used URL. This way I can use the presentation directly from the IDE and publish it without any change.

Example:

sampler: {
    proxyURL: document.location.href.match(/http:\/\/localhost/) ? 'task.php?file=' : ''
}

ThomasWeinert avatar Dec 03 '18 18:12 ThomasWeinert

Ah, I understand better. Two questions:

  1. Can you please rebase on top of the latest master (with #11 applied)?
  2. Would it make more sense instead to allow providing a JS function that fetches the file instead of the fetch we currently use?

ldionne avatar Dec 06 '18 21:12 ldionne

  1. Rebased. Done.

  2. I can imagine several advanced features like that:

a) proxyURL as string with placeholders, allow to transfer information from the data attributes. b) callback function that returns the URL allowing to map/modify it, without caring about the actual fetching c) callback function implements the actual fetching and executes a listener (your suggestion)

Maybe we should move that to a feature request issue and discuss it. It could be useful for some users and does not sound to difficult to implement.

ThomasWeinert avatar Dec 07 '18 14:12 ThomasWeinert