This repository has been archived on 2026-08-27. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
RequestCounter/app/__init__.py
T

56 lines
1.2 KiB
Python
Raw Normal View History

2022-03-26 08:02:25 +08:00
#!/usr/bin/env python3
# -- coding:utf-8 --
# @Author: markushammered@gmail.com
# @Development Tool: PyCharm
# @Create Time: 2022/3/25
# @File Name: __init__.py
2022-04-10 14:31:24 +08:00
import os
2022-03-26 08:02:25 +08:00
from flask import Flask
2022-04-07 21:53:36 +08:00
from flask_sslify import SSLify
from .main import main as main_blueprint
from .api import api as api_blueprint
2022-04-11 21:49:36 +08:00
from .config import config
from .utils.password import generate_pwd
from .utils.logger import CreateLogger
2022-03-27 17:03:20 +08:00
2022-04-11 21:49:36 +08:00
logger = CreateLogger().get_logger()
2022-04-10 14:31:24 +08:00
2022-03-26 08:41:15 +08:00
def create_app(config_name):
2022-04-10 14:31:24 +08:00
"""
创建 app
:param config_name:
:return:
"""
2022-03-26 08:02:25 +08:00
app = Flask(__name__)
2022-03-26 08:41:15 +08:00
app.config.from_object(config[config_name])
config[config_name].init_app(app)
2022-04-10 14:31:24 +08:00
if os.environ.get('SSL_REDIRECT'):
SSLify(app)
2022-03-26 08:41:15 +08:00
app.register_blueprint(main_blueprint)
2022-04-09 11:11:13 +08:00
app.register_blueprint(api_blueprint, url_prefix='/api/v1/')
2022-03-26 08:02:25 +08:00
2022-04-11 21:49:36 +08:00
CreateLogger.init_app(app)
2022-04-10 14:31:24 +08:00
if not os.getenv('ACCESS_KEY'):
2022-04-11 21:49:36 +08:00
access_key = generate_pwd(32)
2022-04-10 14:31:24 +08:00
os.environ['ACCESS_KEY'] = access_key
else:
access_key = os.getenv('ACCESS_KEY')
2022-04-11 21:49:36 +08:00
logger.info('Access Key: {}'.format(access_key))
2022-04-10 14:31:24 +08:00
2022-03-26 08:02:25 +08:00
return app
2022-03-26 09:07:54 +08:00
2022-03-26 08:41:15 +08:00
2022-04-02 18:03:25 +08:00
__all__ = [
'db',
'main',
'tests',
'utils',
2022-04-11 21:49:36 +08:00
'logger',
2022-04-02 18:03:25 +08:00
'create_app'
]