Commit fa9909d4 authored by Antoine Beaupré's avatar Antoine Beaupré

don't use blueprints, just properly setup static routes

parent 3cc5b337
......@@ -25,19 +25,17 @@ import os.path
import re
import click
from flask import Flask, Blueprint, current_app
from flask import Flask
from jinja2 import Template
from debmans.utils import find_static_file
from debmans.renderer import find_files, ManpageRenderer
# we need to use a blueprint because we dynamically create the Flask
# app with a :attr:`static_folder` that is based on the `--output`
# flag or whatever outside config
blueprint = Blueprint('search', __name__)
app = Flask( __name__, static_url_path='')
@blueprint.route('/search/<pattern>')
@app.route('/search/<pattern>')
def search(pattern):
'''respond to searches requests
......@@ -70,8 +68,8 @@ def search(pattern):
# XXX: not sure this is the best structure
manpages = {} # suite -> (name, section)
i = 0
assert current_app.static_folder
for path in find_files(current_app.static_folder, patterns):
assert app.static_folder
for path in find_files(app.static_folder, patterns):
i += 1
# XXX: again
m = re.search(ManpageRenderer.pattern, path)
......@@ -107,6 +105,22 @@ def search(pattern):
return r.render(content=content, suites={})
@app.route('/')
def root():
'''serve the default HTML file
this route should never be hit in a production environment'''
return app.send_static_file('index.html')
@app.route('/<path:path>')
def static_files(path):
'''serve static files in development
this roule should never be hit in a production environment'''
return app.send_from_directory(app.static_folder, path)
@click.command()
@click.option('-p', '--port', default=8000, show_default=True,
help='port to start the server on')
......@@ -137,15 +151,8 @@ def serve(obj, port):
main(obj['output'], port)
@blueprint.route('/')
def root():
return current_app.send_static_file('index.html')
def main(output, port=8000):
output = os.path.abspath(output)
app = Flask(__name__, static_folder=output, static_url_path='')
app.register_blueprint(blueprint)
app.static_folder = os.path.abspath(output)
app.run(port=port)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment