Open marcus-j-davies opened 10 months ago
Thank you for this suggestion. This is a good idea to alllow args and env vars and I will look to implement this in an upcoming update. I am also glad to hear that it works in on the Mac platform. I have not tested it there.
In a similar vein, it would be great to an env var (or otherwise) to run the application at a suburl (e.g., https://site.example.com/lxconsole) -- whether directly or as a wsgi application under nginx or apache. It looks like the templates have a whole bunch of hard coded links to "../static" which currently prevent that even if you change or wrap the flask routes themselves.
UPDATE -- I messed around with setting "SCRIPT_NAME" environment variable and running the app via gunicorn. And, indeed, all those "../static" links seem to be preventing that from working. Per my very tenuous understanding gleaned from Google (e.g., https://wlog.viltstigen.se/articles/2021/09/13/flask-application-behind-a-reverse-proxy/ and https://github.com/openanalytics/shinyproxy-flask-demo), it seems like that should be solvable by using "url_for" in all of the templates. Unfortunately, when I tried to head down that path via sed, I couldn't quite pull it all together (I made some progress by replacing the "link rel href" lines for stylesheets, but when I tried to move on to .js scripts and img/svg references everything sort of fell apart on me.)
@marcus-j-davies the latest update now allows for FLASK_RUN_PORT and FLASK_RUN_HOST environment variables as well as --host and --port command-line args.
@skug67 I can update the url_for options and am looking into getting this redirect option working on my end.
@skug67 Version 0.4.7 should now work for you. Here is what I used in my NGINX config.
server {
...
location /test/ {
proxy_pass http://127.0.0.1:8001;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Prefix /;
}
}
And then I ran the application with gunicorn passing in the SCRIPT_NAME var to match the location
gunicorn -e SCRIPT_NAME=/test -b 0.0.0.0:8001 run:app
I am using this on a MAC, where port 5000 was in use. So, to allow control over this. I think allowing overrides with Environment Vars or Arguments.
Arguments should take priority over Environment Vars
I don't have the means to PR this at the moment, so here is a code snippet (run.py)
Examples: