示例#1
0
文件: app.py 项目: huwshimi/jaas.ai
def create_app(testing=False):
    app = flask.Flask(__name__,
                      template_folder='../templates',
                      static_folder='../static')

    app.testing = testing

    app.wsgi_app = ProxyFix(app.wsgi_app)
    if app.debug:
        app.wsgi_app = DebuggedApplication(app.wsgi_app)

    app.url_map.strict_slashes = False

    if not testing:
        talisker.flask.register(app)

        prometheus_flask_exporter.PrometheusMetrics(
            app,
            group_by_endpoint=True,
            buckets=[0.25, 0.5, 0.75, 1, 2],
            path=None)

        init_extensions(app)

    app.before_request(clear_trailing_slash)
    app.after_request(add_headers)

    init_handler(app)
    init_blueprint(app)

    return app
示例#2
0
def create_app(testing=False):
    app = flask.Flask(
        __name__, template_folder='../templates', static_folder='../static')

    app.config.from_object('webapp.config')
    app.testing = testing

    app.wsgi_app = ProxyFix(app.wsgi_app)
    if app.debug:
        app.wsgi_app = DebuggedApplication(app.wsgi_app)

    app.url_map.strict_slashes = False
    app.url_map.converters['regex'] = helpers.RegexConverter

    if not testing:
        talisker.flask.register(app)

        prometheus_flask_exporter.PrometheusMetrics(
            app,
            group_by_endpoint=True,
            buckets=[0.25, 0.5, 0.75, 1, 2],
            path=None
        )

        init_extensions(app)

    app.config.from_object('webapp.configs.' + app.config['WEBAPP'])
    set_handlers(app)

    if app.config['WEBAPP'] == 'snapcraft':
        init_snapcraft(app)
    else:
        init_brandstore(app)

    return app
# Local
from webapp.models import DiscourseDocs, RedirectFoundError

discourse = DiscourseDocs(base_url="https://forum.snapcraft.io/",
                          frontpage_id=3781)

app = flask.Flask(__name__)
app.template_folder = "../templates"
app.static_folder = "../static"
app.url_map.strict_slashes = False

if not app.debug:
    metrics = prometheus_flask_exporter.PrometheusMetrics(
        app,
        group_by_endpoint=True,
        buckets=[0.25, 0.5, 0.75, 1, 2],
        path=None)
    metrics.start_http_server(port=9990, endpoint="/")


@app.errorhandler(404)
def page_not_found(e):
    frontpage, nav_html = discourse.get_frontpage()

    return flask.render_template("404.html", nav_html=nav_html), 404


@app.errorhandler(410)
def page_deleted(e):
    frontpage, nav_html = discourse.get_frontpage()