Skip to content

Commit

Permalink
Merge c3c53e6 into 510e7a5
Browse files Browse the repository at this point in the history
  • Loading branch information
Avsecz committed Oct 8, 2017
2 parents 510e7a5 + c3c53e6 commit a1c4c3c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,4 @@ sacredboard/Scripts/

\.idea/
node_modules
*~
31 changes: 31 additions & 0 deletions sacredboard/app/webapi/proxy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# prody implementation

# http://blog.macuyiko.com/post/2016/fixing-flask-url_for-when-behind-mod_proxy.html


class ReverseProxied(object):
"""
Allow to use a reverse proxy
http://blog.macuyiko.com/post/2016/fixing-flask-url_for-when-behind-mod_proxy.html
"""

def __init__(self, app, script_name=None, scheme=None, server=None):
self.app = app
self.script_name = script_name
self.scheme = scheme
self.server = server

def __call__(self, environ, start_response):
script_name = environ.get('HTTP_X_SCRIPT_NAME', '') or self.script_name
if script_name:
environ['SCRIPT_NAME'] = script_name
path_info = environ['PATH_INFO']
if path_info.startswith(script_name):
environ['PATH_INFO'] = path_info[len(script_name):]
scheme = environ.get('HTTP_X_SCHEME', '') or self.scheme
if scheme:
environ['wsgi.url_scheme'] = scheme
server = environ.get('HTTP_X_FORWARDED_SERVER', '') or self.server
if server:
environ['HTTP_HOST'] = server
return self.app(environ, start_response)
9 changes: 8 additions & 1 deletion sacredboard/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from sacredboard.app.data.filestorage import FileStorage
from sacredboard.app.data.mongodb import PyMongoDataAccess
from sacredboard.app.webapi import routes, metrics
from sacredboard.app.webapi.proxy import ReverseProxied

locale.setlocale(locale.LC_ALL, '')
app = Flask(__name__)
Expand All @@ -41,11 +42,15 @@
"File Storage observer. (experimental)")
@click.option("--no-browser", is_flag=True, default=False,
help="Do not open web browser automatically.")
@click.option("-sub_url", default="/",
help="Run the app on a sub-url. Example '-sub_url /sacredboard/' "
"maps localhost:5000/ -> localhost:5000/sacredboard/. "
"Useful with http proxy.")
@click.option("--debug", is_flag=True, default=False,
help="Run the application in Flask debug mode "
"(for development).")
@click.version_option()
def run(debug, no_browser, m, mu, mc, f):
def run(debug, no_browser, m, mu, mc, f, sub_url):
"""
Sacredboard.
Expand Down Expand Up @@ -93,6 +98,8 @@ def run(debug, no_browser, m, mu, mc, f):

app.config['DEBUG'] = debug
app.debug = debug
if sub_url is not "/":
app.wsgi_app = ReverseProxied(app.wsgi_app, script_name=sub_url)
jinja_filters.setup_filters(app)
routes.setup_routes(app)
metrics.initialize(app)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ define(["runs/Metric", "knockout", "jquery"], function (Metric, ko, $) {
}
var self = this;
this._fetchingInProgress = true;
$.getJSON("/api/run/" + this._runId + "/metric/" + this._metricId,
$.getJSON("api/run/" + this._runId + "/metric/" + this._metricId,
function (data) {
self._values(data["values"]);
self._steps(data["steps"]);
Expand Down
4 changes: 2 additions & 2 deletions sacredboard/static/scripts/runs/runTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ define(["bootstrap", "datatable", "datatables-bootstrap", "runs/detailView", "jq
* and additional URL parameters to be passed to the backend.
*/
ajax: {
url: "/api/run",
url: "api/run",
data: function (request) {
request.queryFilter = JSON.stringify(createRunTable.queryFilter);

Expand Down Expand Up @@ -132,7 +132,7 @@ define(["bootstrap", "datatable", "datatables-bootstrap", "runs/detailView", "jq
var id = row.data().id;
var loadDetailData = function () {
$.ajax({
url: "/api/run/" + id
url: "api/run/" + id
}).done(function (data) {
if (data.data[0].id != row.data().id) {
/* Before this ajax function was called,
Expand Down

0 comments on commit a1c4c3c

Please sign in to comment.