mirror of
https://github.com/mskatoni/ni-mail.git
synced 2026-08-29 12:07:24 +08:00
42 lines
1.0 KiB
Python
42 lines
1.0 KiB
Python
import os
|
|
from flask import Flask, render_template, jsonify
|
|
from dotenv import load_dotenv
|
|
from app.db import db
|
|
from app.api import accounts, emails
|
|
|
|
__version__ = "1.1.0"
|
|
|
|
def create_app():
|
|
load_dotenv()
|
|
app = Flask(__name__)
|
|
|
|
data_dir = os.getenv("DATA_DIR", os.getcwd())
|
|
default_db = f"sqlite:///{os.path.join(data_dir, 'ni_mail.db')}"
|
|
db_path = os.getenv("DATABASE_URL", default_db)
|
|
|
|
app.config["SQLALCHEMY_DATABASE_URI"] = db_path
|
|
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
|
|
app.config["SECRET_KEY"] = os.getenv("SECRET_KEY", "ni-mail-secret-key-v1.1.0")
|
|
|
|
db.init_app(app)
|
|
|
|
app.register_blueprint(accounts.bp)
|
|
app.register_blueprint(emails.bp)
|
|
|
|
@app.route("/")
|
|
def index():
|
|
return render_template("index.html")
|
|
|
|
@app.route("/health")
|
|
def health():
|
|
return jsonify({
|
|
"status": "ok",
|
|
"app": "ni-mail",
|
|
"version": __version__
|
|
})
|
|
|
|
with app.app_context():
|
|
db.create_all()
|
|
|
|
return app
|