36 lines
762 B
Python
36 lines
762 B
Python
from flask import Flask, g, jsonify, request
|
|
import sqlite3
|
|
from database import SmartCursor, get_db, init_db
|
|
from flask_sqlalchemy import SQLAlchemy
|
|
|
|
db = SQLAlchemy()
|
|
|
|
|
|
def create_app():
|
|
app = Flask(__name__)
|
|
|
|
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:////data/tables.db"
|
|
|
|
db.init_app(app)
|
|
|
|
@app.teardown_appcontext
|
|
def close_connection(exception):
|
|
db = getattr(g, "_database", None)
|
|
if db is not None:
|
|
db.close()
|
|
|
|
import tables
|
|
import auth
|
|
|
|
app.register_blueprint(tables.tables, url_prefix="/api")
|
|
app.register_blueprint(auth.auth, url_prefix="/api/auth")
|
|
|
|
with app.app_context():
|
|
init_db(get_db())
|
|
|
|
return app
|
|
|
|
|
|
if __name__ == "__main__":
|
|
create_app().run(debug=True)
|