58 lines
1.7 KiB
Python
58 lines
1.7 KiB
Python
import os
|
|
import time
|
|
from flask import Flask, g, request
|
|
from flask_login import LoginManager, current_user
|
|
from uuid import uuid4
|
|
from app.main import bp as main_bp
|
|
# from app.auth import bp as auth_bp
|
|
from app import config
|
|
from app.playgrounds import bp as pg_bp
|
|
# from app_common import login_manager
|
|
from authlib.integrations.requests_client import OAuth2Session
|
|
# from app.auth import google
|
|
|
|
|
|
def create_app(app_name):
|
|
app_root_path = os.path.abspath(os.path.dirname(__file__))
|
|
# app = Flask(app_name, template_folder=os.path.join(app_root_path, 'templates'), static_folder=os.path.join(app_root_path, 'static'))
|
|
app = Flask(__name__)
|
|
|
|
app.secret_key = str(uuid4())
|
|
|
|
from app import model
|
|
|
|
# login_manager.init_app(app)
|
|
|
|
app.config.from_object(config)
|
|
|
|
app.register_blueprint(main_bp)
|
|
app.register_blueprint(pg_bp)
|
|
# app.register_blueprint(auth_bp)
|
|
|
|
# app.register_blueprint(google.app)
|
|
|
|
@app.before_request
|
|
def before_request():
|
|
|
|
g.start = time.time()
|
|
|
|
@app.after_request
|
|
def after_request(response):
|
|
if hasattr(g, 'start'):
|
|
request_time = time.time() - g.start
|
|
else:
|
|
request_time = 'N/A '
|
|
# app.logger.info(f'HTTP request completed (method={request.method}, path={request.path}, status_code={response.status_code}, request_time={request_time}s, '
|
|
# f'user={current_user.id if current_user and hasattr(current_user, "id") else "None"}).')
|
|
return response
|
|
|
|
app.logger.info('Config Values:\n -' + '\n -'.join([f'{k}: {app.config[k]}' for k in app.config]))
|
|
|
|
return app
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app = create_app(__name__)
|
|
app.run()
|
|
|