Skip to content

Commit

Permalink
Refactor backend connection
Browse files Browse the repository at this point in the history
  • Loading branch information
israelias committed Jun 13, 2024
1 parent 9b9391f commit 4c787e8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions backend/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.9.19
24 changes: 15 additions & 9 deletions backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,21 @@
from resources.listing import ListingAPI, ListingsAPI, listing_ns, listings_ns
from resources.user import UserAPI, UsersAPI, user_ns, users_ns



# Heroku-specific postgresql config
uri = os.getenv("DATABASE_URL")
if uri.startswith("postgres://"):
uri = uri.replace("postgres://", "postgresql://", 1)
# uri = os.getenv("DATABASE_URL")
# if uri and uri.startswith("postgres://"):
# uri = uri.replace("postgres://", "postgresql://", 1)


if not os.path.exists("env.py"):
pass
else:
import env

debug = os.environ.get("DEVELOPMENT")

# ===========================================================================
# * `Flask App and Configs`
# ? Executes Flask app deployment
Expand All @@ -42,7 +46,7 @@

# Initialize `app`
app = Flask(__name__)
# basedir = os.path.abspath(os.path.dirname(__file__))
basedir = os.path.abspath(os.path.dirname(__file__))


# Initialize `Blueprint API`
Expand All @@ -52,11 +56,13 @@


# Apply database configs
# Development DB
# app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join(basedir, "db.sqlite")

# Production DB
app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get("SQLALCHEMY_DATABASE_URI")
if debug:
# Development DB
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join(basedir, "db.sqlite")
else:
# Production DB
app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get("DATABASE_URL")
# Apply db settings
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
app.config["PROPAGATE_EXCEPTIONS"] = True

Expand Down

0 comments on commit 4c787e8

Please sign in to comment.