~roshless/nnrss

ref: 1d0c090620782aa50408b30d2701a44942800232 nnrss/nnrss/__init__.py -rw-r--r-- 1.1 KiB
1d0c0906Roshless feat: add prometheus metrics 1 year, 14 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from flask import Flask

__author__ = "Roshless <me@roshless.com>"
__version__ = "0.2"


def create_app():
    from nnrss.config import ACCOUNT
    from nnrss.models import SESSION

    app = Flask(__name__)
    from nnrss.api import API  # noQA isort:skip
    from nnrss.views import DEFAULT_WEB  # noQA isort:skip

    if ACCOUNT.api_enabled:
        app.register_blueprint(API, url_prefix="/api")
    if ACCOUNT.interface_enabled:
        app.register_blueprint(DEFAULT_WEB, url_prefix="/")
    if ACCOUNT.metrics_enabled:
        from prometheus_flask_exporter import NO_PREFIX
        from prometheus_flask_exporter.multiprocess import PrometheusMetrics

        metrics = PrometheusMetrics(app, defaults_prefix=NO_PREFIX)
        metrics.info("app_version", "Application version", version=__version__)

    app.secret_key = ACCOUNT.get_secret_key()

    app.config.update(
        SESSION_COOKIE_HTTPONLY=True,
        SESSION_COOKIE_SAMESITE="Lax",
    )

    @app.teardown_appcontext
    def shutdown_session(exception=None):
        SESSION.remove()

    return app


APP = create_app()