Skip to content

Commit

Permalink
Merge pull request #2785 from timkpaine/reverse-proxy
Browse files Browse the repository at this point in the history
don't use absolute path in redirect for visualizer
  • Loading branch information
honnix authored Sep 24, 2020
2 parents 92fe69e + ba5ff73 commit d4eb8a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion luigi/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,13 @@ def get(self, name):

class RootPathHandler(BaseTaskHistoryHandler):
def get(self):
self.redirect("/static/visualiser/index.html")
# we omit the leading slash in case the visualizer is behind a different
# path (as in a reverse proxy setup)
#
# For example, if luigi is behind my.app.com/my/luigi/, we want / to
# redirect relative (so it goes to my.app.com/my/luigi/static/visualizer/index.html)
# instead of absolute (which would be my.app.com/static/visualizer/index.html)

This comment has been minimized.

Copy link
@tashrifbillah

tashrifbillah Nov 13, 2020

Contributor

Better wording for the comment:

# For example, if luigi is behind my.app.com/my/luigi/, we want / to
# redirect relatively with respect to my.app.com/my/luigi/ (so it goes to my.app.com/my/luigi/static/visualizer/index.html)
# instead of absolutely with respect to my.app.com/ (which would go to my.app.com/static/visualizer/index.html)
self.redirect("static/visualiser/index.html")

def head(self):
"""HEAD endpoint for health checking the scheduler"""
Expand Down
5 changes: 5 additions & 0 deletions test/server_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ def test_404(self):
def test_api_404(self):
self._test_404('/api/foo')

def test_root_redirect(self):
response = self.fetch("/", follow_redirects=False)
self.assertEqual(response.code, 302)
self.assertEqual(response.headers['Location'], 'static/visualiser/index.html') # assert that doesnt beging with leading slash !

This comment has been minimized.

Copy link
@tashrifbillah

tashrifbillah Nov 13, 2020

Contributor

TYPO: begin

def test_api_preflight_cors_headers(self):
response = self.fetch('/api/graph', method='OPTIONS', headers={'Origin': 'foo'})
headers = dict(response.headers)
Expand Down

0 comments on commit d4eb8a6

Please sign in to comment.