-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
47 lines (38 loc) · 1.28 KB
/
app.py
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
41
42
43
44
45
46
47
from flask import Flask
from flask.logging import default_handler
from flask_bootstrap import Bootstrap5
from pathlib import Path
from models import db
import flask_cors
import atexit
import json
import os
import logging
import logging.config
from tools import get_secret_key
from views.auth import auth
from views.settings import settings
from views.capture import capture
from views.routes import routes
def create_app(config_file):
config_json = json.load(open(config_file))
instance_path = os.path.abspath(config_json["INSTANCE_PATH"])
app = Flask(__name__, instance_path=instance_path)
Path(config_json["LOGS_PATH"]).mkdir(parents=False, exist_ok=True)
app.logger.removeHandler(default_handler)
logging.config.dictConfig(config_json["LOGGER_CONFIG"])
app.config.from_file(config_file, load=json.load)
app.config["SECRET_KEY"] = get_secret_key()
db.init_app(app)
bootstrap = Bootstrap5(app)
flask_cors.CORS(app) # authorize cross-origin AJAX for Obsidian
app.register_blueprint(auth)
app.register_blueprint(settings)
app.register_blueprint(capture)
app.register_blueprint(routes)
with app.app_context():
db.create_all()
return app
if __name__ == "__main__" :
app = create_app("config.json")
app.run()