Fix http router so it can handle /{ext_name} same as /{ext_name}/

This commit is contained in:
dz0ny 2014-06-21 15:05:13 +02:00
parent e7d3837840
commit 7c428ce8d2
3 changed files with 13 additions and 3 deletions

View File

@ -96,14 +96,14 @@ class HttpFrontend(pykka.ThreadingActor, CoreListener):
result = []
for static in self.statics:
result.append((
r'/%s/(.*)' % static['name'],
r'/{}/?(.*)'.format(static['name']),
handlers.StaticFileHandler,
{
'path': static['path'],
'default_filename': 'index.html'
}
))
logger.debug('Loaded HTTP extension: %s', static['name'])
logger.debug('Loaded static HTTP extension: %s', static['name'])
return result
def _publish_zeroconf(self):

View File

@ -23,7 +23,7 @@ def mopidy_app_factory(config, core):
(r'/rpc', JsonRpcHandler, {
'core': core,
}),
(r'/(.*)', StaticFileHandler, {
(r'/?(.*)', StaticFileHandler, {
'path': os.path.join(os.path.dirname(__file__), 'data'),
'default_filename': 'mopidy.html'
}),

View File

@ -53,6 +53,16 @@ class HttpServerTest(tornado.testing.AsyncHTTPTestCase):
response.headers['X-Mopidy-Version'], mopidy.__version__)
self.assertEqual(response.headers['Cache-Control'], 'no-cache')
def test_mopidy_should_return_index_no_slash(self):
response = self.fetch('/mopidy', method='GET')
self.assertIn(
'Here you can see events arriving from Mopidy in real time:',
tornado.escape.to_unicode(response.body))
self.assertEqual(
response.headers['X-Mopidy-Version'], mopidy.__version__)
self.assertEqual(response.headers['Cache-Control'], 'no-cache')
def test_should_return_js(self):
response = self.fetch('/mopidy/mopidy.js', method='GET')