diff --git a/mopidy/http/actor.py b/mopidy/http/actor.py index 3ab0a480..e834d897 100644 --- a/mopidy/http/actor.py +++ b/mopidy/http/actor.py @@ -68,13 +68,16 @@ class HttpFrontend(pykka.ThreadingActor, CoreListener): request_handlers.extend(self._get_static_request_handlers()) # Either default Mopidy or user defined path to files - static_dir = self.config['http']['static_dir'] - data_dir = os.path.join(os.path.dirname(__file__), 'data') - root_handler = (r'/(.*)', handlers.StaticFileHandler, { - 'path': static_dir if static_dir else data_dir, - 'default_filename': 'index.html' - }) - request_handlers.append(root_handler) + if self.config['http']['static_dir']: + request_handlers.append((r'/(.*)', handlers.StaticFileHandler, { + 'path': self.config['http']['static_dir'], + 'default_filename': 'index.html', + })) + else: + request_handlers.append((r'/', tornado.web.RedirectHandler, { + 'url': '/mopidy/', + 'permanent': False, + })) logger.debug( 'HTTP routes from extensions: %s', diff --git a/mopidy/http/data/index.html b/mopidy/http/data/index.html deleted file mode 100644 index 2376d3aa..00000000 --- a/mopidy/http/data/index.html +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - Mopidy - - - -
-

Mopidy

- -

This web server is a part of the Mopidy music server. To learn more - about Mopidy, please visit - www.mopidy.com.

-
- -
-

Static content serving

- -

To see your own content instead of this placeholder page, change the - config value http/static_dir to point to the directory - containing your static files. This can be used to host e.g. a pure - HTML/CSS/JavaScript Mopidy client.

- -

If you replace this page with your own content, the Mopidy resources - and APIs at /mopidy/ will still be available.

-
- - diff --git a/tests/http/test_server.py b/tests/http/test_server.py index 79fb6866..bb93785a 100644 --- a/tests/http/test_server.py +++ b/tests/http/test_server.py @@ -39,21 +39,31 @@ class HttpServerTest(tornado.testing.AsyncHTTPTestCase): return tornado.web.Application(http_frontend._get_request_handlers()) -class RootAppTest(HttpServerTest): - def test_should_return_index(self): - response = self.fetch('/', method='GET') +class RootRedirectTest(HttpServerTest): + def test_should_redirect_to_mopidy_app(self): + response = self.fetch('/', method='GET', follow_redirects=False) - self.assertIn( - 'This web server is a part of the Mopidy music server.', - tornado.escape.to_unicode(response.body)) - self.assertEqual( - response.headers['X-Mopidy-Version'], mopidy.__version__) - self.assertEqual(response.headers['Cache-Control'], 'no-cache') + self.assertEqual(response.code, 302) + self.assertEqual(response.headers['Location'], '/mopidy/') + + +class LegacyStaticDirAppTest(HttpServerTest): + def get_config(self): + config = super(LegacyStaticDirAppTest, self).get_config() + config['http']['static_dir'] = os.path.dirname(__file__) + return config + + def test_should_return_index(self): + response = self.fetch('/', method='GET', follow_redirects=False) + + self.assertEqual(response.code, 404, 'No index.html in this dir') def test_should_return_static_files(self): - response = self.fetch('/mopidy.css', method='GET') + response = self.fetch('/test_server.py', method='GET') - self.assertIn('html {', tornado.escape.to_unicode(response.body)) + self.assertIn( + 'test_should_return_static_files', + tornado.escape.to_unicode(response.body)) self.assertEqual( response.headers['X-Mopidy-Version'], mopidy.__version__) self.assertEqual(response.headers['Cache-Control'], 'no-cache')