Skip to content

Commit

Permalink
Completed app factory implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
davewalker5 committed Feb 19, 2022
1 parent 14c1f34 commit 050915e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
1 change: 1 addition & 0 deletions run_web.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export PROJECT_ROOT=$( cd "$(dirname "$0")" ; pwd -P )
source "$PROJECT_ROOT/venv/bin/activate"
export PYTHONPATH="$PROJECT_ROOT/src"
export NATURE_RECORDER_DB="$PROJECT_ROOT/data/naturerecorder.db"
export FLASK_ENV=development
python -m naturerec_web
2 changes: 0 additions & 2 deletions src/naturerec_web/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ def create_app(environment="production"):

config_object = f"naturerec_web.config.{'ProductionConfig' if environment == 'production' else 'DevelopmentConfig'}"
app.config.from_object(config_object)
print(config_object)
print(os.environ["SECRET_KEY"])

# Register the blueprints
app.secret_key = os.environ["SECRET_KEY"]
Expand Down
5 changes: 4 additions & 1 deletion src/naturerec_web/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
from naturerec_web import create_app

environment = sys.argv[1] if len(sys.argv) > 1 else "development"
create_app(environment).run()
if environment == "development":
create_app(environment).run(debug=True, use_reloader=True)
else:
create_app(environment).run(host="0.0.0.0")
11 changes: 4 additions & 7 deletions src/naturerec_web/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
from dotenv import load_dotenv

basedir = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
env_file = os.path.join(basedir, "data", ".env")
if "NATURE_RECORDER_DATA_FOLDER" in os.environ:
env_file = os.path.join(os.environ["NATURE_RECORDER_DATA_FOLDER"], ".env")
else:
env_file = os.path.join(basedir, "data", ".env")
load_dotenv(env_file)


Expand All @@ -15,14 +18,8 @@ class BaseConfig:


class ProductionConfig(BaseConfig):
FLASK_ENV = 'production'
DEBUG = False
TESTING = False
SERVER_NAME = "0.0.0.0"


class DevelopmentConfig(BaseConfig):
FLASK_ENV = 'development'
DEBUG = True
TESTING = True
SERVER_NAME = "127.0.0.1:5000"

0 comments on commit 050915e

Please sign in to comment.