Initial Commit
slip slop
This commit is contained in:
commit
064e672ab7
61 changed files with 3504 additions and 0 deletions
53
app/__init__.py
Normal file
53
app/__init__.py
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
"""Flask application factory."""
|
||||
import os
|
||||
from flask import Flask
|
||||
from flask_cors import CORS
|
||||
from app.extensions import db
|
||||
from app.routes_tunes import tunes_bp
|
||||
from app.routes_instruments import instruments_bp
|
||||
from app.routes_sub import sub_bp
|
||||
from app.routes_sources import sources_bp
|
||||
from app.routes_musicians import musicians_bp
|
||||
from app.routes_tunings import tunings_bp
|
||||
|
||||
|
||||
def create_app():
|
||||
app = Flask(__name__)
|
||||
|
||||
# --- Config ---
|
||||
app.config["SQLALCHEMY_DATABASE_URI"] = os.environ["DATABASE_URL"]
|
||||
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
|
||||
|
||||
# --- CORS ---
|
||||
# CORS_ORIGINS in .env is a comma-separated list of allowed origins.
|
||||
# Defaults to * for local dev. Lock this down in production to your
|
||||
# S3 bucket / CloudFront domain, e.g.:
|
||||
# CORS_ORIGINS=https://yourdomain.com,https://www.yourdomain.com
|
||||
raw = os.environ.get("CORS_ORIGINS", "*")
|
||||
origins = [o.strip() for o in raw.split(",")] if raw != "*" else "*"
|
||||
CORS(app, origins=origins, supports_credentials=False)
|
||||
|
||||
# --- Extensions ---
|
||||
db.init_app(app)
|
||||
|
||||
# --- Blueprints ---
|
||||
app.register_blueprint(tunes_bp)
|
||||
app.register_blueprint(instruments_bp)
|
||||
app.register_blueprint(sub_bp)
|
||||
app.register_blueprint(sources_bp)
|
||||
app.register_blueprint(musicians_bp)
|
||||
app.register_blueprint(tunings_bp)
|
||||
|
||||
# --- Error handlers ---
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
@app.errorhandler(IntegrityError)
|
||||
def handle_integrity_error(e):
|
||||
db.session.rollback()
|
||||
return {"error": "Conflict — duplicate or constraint violation"}, 409
|
||||
|
||||
@app.get("/health")
|
||||
def health():
|
||||
return {"status": "ok"}
|
||||
|
||||
return app
|
||||
Loading…
Add table
Add a link
Reference in a new issue