diff --git a/README.md b/README.md index 881876a..1fbd60c 100644 --- a/README.md +++ b/README.md @@ -48,11 +48,13 @@ The project is designed for deployment on Azure App Service with a MySQL flexibl export FLASK_DEBUG=true flask run --reload ``` + **For Windows, use [`setx`](https://learn.microsoft.com/windows-server/administration/windows-commands/setx) command shown below:** + ```powershell - setx FLASK_APP=app.py - setx FLASK_ENV=development - setx FLASK_DEBUG=true + setx FLASK_APP app.py + setx FLASK_ENV development + setx FLASK_DEBUG true flask run --reload ``` @@ -60,6 +62,32 @@ The project is designed for deployment on Azure App Service with a MySQL flexibl Navigate to project homepage [http://127.0.0.1:5000/](http://127.0.0.1:5000/) or [http://localhost:5000](http://localhost:5000) +### Connect to your Database locally + +This application is configured to work without connecting a database for the pages that doesn't interact with it. If you want to enable database operations you'll need to connect to a database. + +- **Run the following commands to connect to a database:** + + ```bash + export DEPLOYMENT_LOCATION=local + export DB_USER= + export DB_PASSWORD= + export DB_HOST= + export DB_NAME= + ``` + +- **For windows, add configuration using:** + + ```powershell + setx DEPLOYMENT_LOCATION local + setx DB_USER user + setx DB_PASSWORD password + setx DB_HOST host + setx DB_NAME dbname + ``` + +- **Run the development server again.** + ## Deployment This repository is set up for deployment on Azure App Service (w/MySQL flexible server) using the configuration files in the `infra` folder. diff --git a/app.py b/app.py index dec46ab..b4987ee 100644 --- a/app.py +++ b/app.py @@ -38,6 +38,10 @@ print("Loading environment.azure_production.") app.config.from_object('environment.azure_production') setup_db(app) +elif os.environ.get('DEPLOYMENT_LOCATION') == 'local': + print("Loading environment.development.") + app.config.from_object('environment.development') + setup_db(app) else: print("No environment detected.") diff --git a/environment/development.py b/environment/development.py new file mode 100644 index 0000000..57c4de0 --- /dev/null +++ b/environment/development.py @@ -0,0 +1,9 @@ +import os + +# mysql+mysqlconnector://your-username:your-password@localhost/your-schema' +DATABASE_URI = 'mysql+mysqlconnector://{dbuser}:{dbpass}@{dbhost}/{dbname}'.format( + dbuser=os.environ.get('DB_USER'), + dbpass=os.environ.get('DB_PASSWORD'), + dbhost=os.environ.get('DB_HOST'), + dbname=os.environ.get('DB_NAME') +)