35 lines
866 B
Python
35 lines
866 B
Python
import os
|
|
from dotenv import load_dotenv
|
|
from flask import Flask, render_template
|
|
import db
|
|
from test_routes import test_bp
|
|
|
|
load_dotenv()
|
|
|
|
class ContractsApp:
|
|
def __init__(self):
|
|
self.app = Flask(__name__)
|
|
db.ensure_db()
|
|
self.add_routes()
|
|
|
|
def add_routes(self):
|
|
self.app.add_url_rule("/", "index", self.index)
|
|
self.app.add_url_rule("/health", "health", self.health)
|
|
self.app.register_blueprint(test_bp)
|
|
|
|
def index(self):
|
|
conn, _ = db.connect()
|
|
db_status = "connected" if conn else "no DB"
|
|
return render_template("index.html", db_status=db_status)
|
|
|
|
def health(self):
|
|
return "OK", 200, {"Content-Type": "text/plain"}
|
|
|
|
def run(self):
|
|
self.app.run(host="0.0.0.0", port=5000)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app_instance = ContractsApp()
|
|
app_instance.run()
|