39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
import os
|
|
from pathlib import Path
|
|
from dotenv import load_dotenv
|
|
load_dotenv('../.env')
|
|
|
|
class Config(object):
|
|
"""Basic App Configuration"""
|
|
APP_HOST = '0.0.0.0'
|
|
DATA = './data/'
|
|
DEBUG = False
|
|
TESTING = False
|
|
SECRET_KEY = os.getenv('SECRET_KEY')
|
|
SERVER_NAME = os.getenv('SERVER_NAME')
|
|
SESSION_COOKIE_SECURE = True
|
|
|
|
"""Database Driver Configuration"""
|
|
DATABASE_TYPE = os.getenv('DATABASE_TYPE') or 'SQLite'
|
|
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
|
|
|
if DATABASE_TYPE.lower() == 'mysql' and os.getenv('MYSQL_DATABASE') and os.getenv('MYSQL_USER') and os.getenv('MYSQL_PASSWORD'):
|
|
DATABASE_HOST = os.getenv('DATABASE_HOST') or 'localhost'
|
|
DATABASE_PORT = int(os.getenv('DATABASE_PORT') or 3306)
|
|
MYSQL_DATABASE = os.getenv('MYSQL_DATABASE')
|
|
MYSQL_USER = os.getenv('MYSQL_USER')
|
|
MYSQL_PASSWORD = os.getenv('MYSQL_PASSWORD')
|
|
SQLALCHEMY_DATABASE_URI = f'mysql+pymysql://{MYSQL_USER}:{MYSQL_PASSWORD}@{DATABASE_HOST}:{DATABASE_PORT}/{MYSQL_DATABASE}'
|
|
else: SQLALCHEMY_DATABASE_URI = f'sqlite:///{Path(os.path.abspath(f"{DATA}/database.db"))}'
|
|
|
|
class Production(Config): pass
|
|
|
|
class Development(Config):
|
|
APP_HOST = '127.0.0.1'
|
|
DEBUG = True
|
|
SERVER_NAME = '127.0.0.1:5000'
|
|
SESSION_COOKIE_SECURE = False
|
|
|
|
class Testing(Development):
|
|
TESTING = True
|