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

Fix reverse proxy #57

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

Conversation

jamieforth
Copy link

At my institution I can only deploy behind an Apache reverse proxy with a non-root URL.

e.g. http://example.com/my-experiment

The only way I could figure out how to deploy experiment factory in this context was to include the ReverseProxied middleware and change all redirect() calls to use url_for() in place of the absolute urls.

This may or may not be generally useful. It doesn't appear to break existing root deployment, but deploying in a non-root context requires modifying nginx.gunicorn.conf as documented in flask snippet 35.

@vsoch
Copy link
Member

vsoch commented Jan 9, 2018

Oh I think this will be badly needed! I have a few questions before commencing testing!

  • it looks like url_for will serve the same purpose as just going to the url, but adds additional functionality for proxy as well. I'm assuming that the url_for relies on the flask application knowing / understanding the proxy (and this is why you added the wrapper?)
  • we currently serve the main non-flask server (static experiments) separately (nginx) and have flask use the static files from there, and then generate a template by dumping the index.html into it. We also do that by way of (separately) configuring the nginx.conf. How does this solution edit that? (E.g., if we have two places where we are tweaking the nginx.conf, can that be made into one?
  • and stemming from the above question - if we do have two solutions that can be merged into one, can we do this by way of exposing more EXPFACTORY_ environment variable settings (eg. for the host, or to enable a proxy not) so that a new user that wants to generate a container and turn on/off a particular setting can do it easily?

I really like this addition, and want to discuss something that looks like the following:

  1. possible integration of the proxy setup into the flask (as you have done) but then not needing to do it in two places (if you look at the Dockerfile we copy the base template to the location of the nginx server, so likely we want to look there), and having environment EXPFACTORY_ variables determine this functionality
  2. OR in the case that 1 is not possible (for example, adding the proxy isn't as simple as adding some environment variables / if statements determined by them) we would then want a clear set of instructions for the user to get this setup, and of course with reasonable defaults!

I'm excited about this and grateful for the contribution! Just a heads up I'm going to be afk for perhaps a week as I'm about to head in for a procedure. Please take your time in thinking this through, it's a simple (and powerful) change that I would like to add.

Was a Typo: 'ContentType'.
into experiment index.html on install.

Previous solution of appending the template script after the html tag
was unreliable.

SCRIPT_ROOT is necessary for posting to experiment factory deployed
behind a reverse proxy. Experiment must POST to SCRIPT_ROOT + '/save'.

```js
on_finish: function(data) {
  // Get the data.
  var data = jsPsych.data.get();

  var request = $.post(
    SCRIPT_ROOT + '/save',
    {'data': data.json()},
    function() {
      // Success, go to /next.
      document.location = SCRIPT_ROOT + '/next';
    },
    'json')
      .fail(function() {
        // Error, local save.
        data.localSave('json', 'results.json');
        document.location = SCRIPT_ROOT + '/next';
      });
}
```
@vsoch
Copy link
Member

vsoch commented Jan 30, 2018

hey @jamieforth ! See if you can add the functionality without adding an entire new dependency (BeautifulSoup) which tends to be a bit heavy, and doesn't make sense to perform a tiny text parsing function.

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.

None yet

2 participants