64 lines
No EOL
2 KiB
Python
64 lines
No EOL
2 KiB
Python
import os
|
|
from datetime import timedelta
|
|
|
|
basedir = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
class Config:
|
|
"""Base config."""
|
|
SECRET_KEY = os.environ.get('SECRET_KEY', 'dev-key-placeholder')
|
|
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
|
SESSION_COOKIE_SECURE = True
|
|
SESSION_COOKIE_HTTPONLY = True
|
|
REMEMBER_COOKIE_DURATION = timedelta(days=14)
|
|
PERMANENT_SESSION_LIFETIME = timedelta(days=1)
|
|
|
|
@staticmethod
|
|
def init_app(app):
|
|
pass
|
|
|
|
class DevelopmentConfig(Config):
|
|
DEBUG = True
|
|
SESSION_COOKIE_SECURE = False
|
|
SQLALCHEMY_DATABASE_URI = os.environ.get('DEV_DATABASE_URL') or \
|
|
'sqlite:///' + os.path.join(basedir, '..', 'instance', 'development.db')
|
|
|
|
class TestingConfig(Config):
|
|
TESTING = True
|
|
SQLALCHEMY_DATABASE_URI = os.environ.get('TEST_DATABASE_URL') or \
|
|
'sqlite:///' + os.path.join(basedir, '..', 'instance', 'testing.db')
|
|
WTF_CSRF_ENABLED = False
|
|
|
|
class ProductionConfig(Config):
|
|
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \
|
|
'sqlite:///' + os.path.join(basedir, '..', 'instance', 'production.db')
|
|
|
|
@classmethod
|
|
def init_app(cls, app):
|
|
Config.init_app(app)
|
|
|
|
# Production-specific logging
|
|
import logging
|
|
from logging.handlers import RotatingFileHandler
|
|
log_dir = os.path.join(basedir, '..', 'logs')
|
|
os.makedirs(log_dir, exist_ok=True)
|
|
|
|
file_handler = RotatingFileHandler(
|
|
os.path.join(log_dir, 'app.log'),
|
|
maxBytes=10485760, # 10MB
|
|
backupCount=10
|
|
)
|
|
file_handler.setFormatter(logging.Formatter(
|
|
'%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]'
|
|
))
|
|
file_handler.setLevel(logging.INFO)
|
|
app.logger.addHandler(file_handler)
|
|
app.logger.setLevel(logging.INFO)
|
|
app.logger.info('App startup')
|
|
|
|
config = {
|
|
'development': DevelopmentConfig,
|
|
'testing': TestingConfig,
|
|
'production': ProductionConfig,
|
|
|
|
'default': DevelopmentConfig
|
|
} |