from flask import Flask, send_from_directory from database.db import db from config.config import APP_NAME, ENV, get_app_config, get_static_url # Create and configure our Flask app app = Flask(__name__, static_url_path=get_static_url()) app.url_map.strict_slashes = False app.config.from_object(get_app_config()) db.init_app(app) # uri = os.getenv("DATABASE_URL") # or other relevant config var # print(uri) # # if uri and uri.startswith("postgres://"): # # uri = uri.replace("postgres://", "postgresql://", 1) # # app.config["SQLALCHEMY_DATABASE_URI"] = uri # # db = SQLAlchemy(app) # # db.create_all() # # if db.session.query(User).filter_by(username="testuser").first() is not None: # # db.session.add(User(username='testuser', email='admin@example.com')) # # db.session.commit() # # if db.session.query(Entity).filter_by(username="my entity").first() is not None: # # db.session.add(Entity(username='my entity', email='entity@example.com')) # # db.session.commit() # # else: # # print("No database created/linked with this application") # Serve all static assets for the frontend @app.route('/static/<path:path>') def serve_static_files(path): return send_from_directory('static', path) # Register all routes from the blueprints module from blueprints.home import home_blueprint from blueprints.auth import auth_blueprint app.register_blueprint(home_blueprint) app.register_blueprint(auth_blueprint) # @app.route('/test-db') # def test_db(): # try: # rows = "" # for user in db.session.query(User).all(): # rows += str(user) + " " # for e in db.session.query(Entity).all(): # rows += str(e) + " " # print("All rows:", rows) # return rows # except: # return "App database error" # Hook any custom Jinja templating functions from config import CUSTOM_TEMPLATE_FUNCTIONS app.jinja_env.globals.update(CUSTOM_TEMPLATE_FUNCTIONS) if __name__ == '__main__': app.run()