|
|
@@ -3,19 +3,54 @@
|
|
|
Copyright (c) 2019 - present AppSeed.us
|
|
|
"""
|
|
|
|
|
|
-import os
|
|
|
+import os, random, string
|
|
|
|
|
|
class Config(object):
|
|
|
|
|
|
basedir = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
|
|
# Set up the App SECRET_KEY
|
|
|
- # SECRET_KEY = config('SECRET_KEY' , default='S#perS3crEt_007')
|
|
|
- SECRET_KEY = os.getenv('SECRET_KEY', 'S#perS3crEt_007')
|
|
|
+ SECRET_KEY = os.getenv('SECRET_KEY', None)
|
|
|
+ if not SECRET_KEY:
|
|
|
+ SECRET_KEY = ''.join(random.choice( string.ascii_lowercase ) for i in range( 32 ))
|
|
|
|
|
|
- # This will create a file in <app> FOLDER
|
|
|
- SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'db.sqlite3')
|
|
|
- SQLALCHEMY_TRACK_MODIFICATIONS = False
|
|
|
+ SQLALCHEMY_TRACK_MODIFICATIONS = False
|
|
|
+
|
|
|
+ DB_ENGINE = os.getenv('DB_ENGINE' , None)
|
|
|
+ DB_USERNAME = os.getenv('DB_USERNAME' , None)
|
|
|
+ DB_PASS = os.getenv('DB_PASS' , None)
|
|
|
+ DB_HOST = os.getenv('DB_HOST' , None)
|
|
|
+ DB_PORT = os.getenv('DB_PORT' , None)
|
|
|
+ DB_NAME = os.getenv('DB_NAME' , None)
|
|
|
+
|
|
|
+ USE_SQLITE = True
|
|
|
+
|
|
|
+ # try to set up a Relational DBMS
|
|
|
+ if DB_ENGINE and DB_NAME and DB_USERNAME:
|
|
|
+
|
|
|
+ try:
|
|
|
+
|
|
|
+ # Relational DBMS: PSQL, MySql
|
|
|
+ SQLALCHEMY_DATABASE_URI = '{}://{}:{}@{}:{}/{}'.format(
|
|
|
+ DB_ENGINE,
|
|
|
+ DB_USERNAME,
|
|
|
+ DB_PASS,
|
|
|
+ DB_HOST,
|
|
|
+ DB_PORT,
|
|
|
+ DB_NAME
|
|
|
+ )
|
|
|
+
|
|
|
+ USE_SQLITE = False
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+
|
|
|
+ print('> Error: DBMS Exception: ' + str(e) )
|
|
|
+ print('> Fallback to SQLite ')
|
|
|
+
|
|
|
+ if USE_SQLITE:
|
|
|
+
|
|
|
+ # This will create a file in <app> FOLDER
|
|
|
+ SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'db.sqlite3')
|
|
|
|
|
|
# Assets Management
|
|
|
ASSETS_ROOT = os.getenv('ASSETS_ROOT', '/static/assets')
|
|
|
@@ -37,16 +72,6 @@ class ProductionConfig(Config):
|
|
|
REMEMBER_COOKIE_HTTPONLY = True
|
|
|
REMEMBER_COOKIE_DURATION = 3600
|
|
|
|
|
|
- # PostgreSQL database
|
|
|
- SQLALCHEMY_DATABASE_URI = '{}://{}:{}@{}:{}/{}'.format(
|
|
|
- os.getenv('DB_ENGINE' , 'mysql'),
|
|
|
- os.getenv('DB_USERNAME' , 'appseed_db_usr'),
|
|
|
- os.getenv('DB_PASS' , 'pass'),
|
|
|
- os.getenv('DB_HOST' , 'localhost'),
|
|
|
- os.getenv('DB_PORT' , 3306),
|
|
|
- os.getenv('DB_NAME' , 'appseed_db')
|
|
|
- )
|
|
|
-
|
|
|
|
|
|
class DebugConfig(Config):
|
|
|
DEBUG = True
|