Skip to content

Commit

Permalink
manager: if serving UI, serve from /ui/
Browse files Browse the repository at this point in the history
Routing patterns in Flask should be unique[1]. Serve the UI in the
development webserver from /ui and add a redirect on /.

[1] http://flask.pocoo.org/docs/0.10/design/#the-routing-system
  • Loading branch information
rjw57 committed Oct 24, 2014
1 parent 64162ec commit e1c8663
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions tawhiri/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"""
import os
from flask import send_file, send_from_directory
from flask import send_file, send_from_directory, redirect, url_for
from flask.ext.script import Manager
from .api import app
manager = Manager(app)
Expand All @@ -30,12 +30,16 @@ def main():

ui_dir = app.config.get('UI_DIR')
if ui_dir is not None:
@app.route('/<path:path>')
@app.route('/ui/<path:path>')
def send_ui(path):
return send_from_directory(ui_dir, path)

@app.route('/')
@app.route('/ui/')
def send_index():
return send_file(os.path.join(ui_dir, 'index.html'))

@app.route('/')
def send_ui_redirect():
return redirect(url_for('send_index'))

return manager.run()

0 comments on commit e1c8663

Please sign in to comment.