diff --git a/luigi/server.py b/luigi/server.py index f8c226d65c..50948624d3 100644 --- a/luigi/server.py +++ b/luigi/server.py @@ -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) + self.redirect("static/visualiser/index.html") def head(self): """HEAD endpoint for health checking the scheduler""" diff --git a/test/server_test.py b/test/server_test.py index 23000f1c94..f142523e3a 100644 --- a/test/server_test.py +++ b/test/server_test.py @@ -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 ! + def test_api_preflight_cors_headers(self): response = self.fetch('/api/graph', method='OPTIONS', headers={'Origin': 'foo'}) headers = dict(response.headers)