45 lines
960 B
Python
45 lines
960 B
Python
import os
|
|
import sqlite3
|
|
|
|
from flask import Flask, g, redirect, url_for
|
|
|
|
from config import DB_PATH, SECRET_KEY
|
|
from database.init_db import init_db
|
|
|
|
|
|
def create_app():
|
|
app = Flask(__name__)
|
|
app.secret_key = SECRET_KEY
|
|
app.config["MAX_CONTENT_LENGTH"] = 16 * 1024 * 1024
|
|
|
|
os.makedirs(os.path.dirname(DB_PATH), exist_ok=True)
|
|
|
|
with sqlite3.connect(DB_PATH) as conn:
|
|
init_db(conn)
|
|
|
|
@app.before_request
|
|
def open_db():
|
|
if "db" not in g:
|
|
g.db = sqlite3.connect(DB_PATH)
|
|
g.db.row_factory = sqlite3.Row
|
|
|
|
@app.teardown_appcontext
|
|
def close_db(exception):
|
|
db = g.pop("db", None)
|
|
if db is not None:
|
|
db.close()
|
|
|
|
from routes import bp
|
|
|
|
app.register_blueprint(bp)
|
|
|
|
@app.route("/")
|
|
def index():
|
|
return redirect(url_for("main.documents_1c"))
|
|
|
|
return app
|
|
|
|
|
|
if __name__ == "__main__":
|
|
create_app().run(debug=True, host="0.0.0.0", port=5000)
|