mirror of
https://0xacab.org/jvoisin/mat2-web.git
synced 2025-02-24 00:59:59 -05:00
47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
import os
|
|
import jinja2
|
|
|
|
from matweb import utils, rest_api, frontend
|
|
from flask import Flask
|
|
from flask_restful import Api
|
|
from flask_cors import CORS
|
|
from flasgger import Swagger
|
|
|
|
|
|
def create_app(test_config=None):
|
|
app = Flask(__name__)
|
|
app.config['SECRET_KEY'] = os.urandom(32)
|
|
app.config['UPLOAD_FOLDER'] = os.environ.get('MAT2_WEB_DOWNLOAD_FOLDER', './uploads/')
|
|
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16MB
|
|
app.config['CUSTOM_TEMPLATES_DIR'] = 'custom_templates'
|
|
app.config['SWAGGER'] = {
|
|
'title': 'Mat2 Web API',
|
|
'version': '1.0.0',
|
|
'basePath': '/api'
|
|
}
|
|
# optionally load settings from config.py
|
|
app.config.from_object('config')
|
|
|
|
if test_config is not None:
|
|
app.config.update(test_config)
|
|
|
|
# Non JS Frontend
|
|
app.jinja_loader = jinja2.ChoiceLoader([ # type: ignore
|
|
jinja2.FileSystemLoader(app.config['CUSTOM_TEMPLATES_DIR']),
|
|
app.jinja_loader,
|
|
])
|
|
app.register_blueprint(frontend.routes)
|
|
|
|
# Restful API hookup
|
|
app.register_blueprint(rest_api.api_bp)
|
|
Swagger(app)
|
|
CORS(app, resources={r"/api/*": {"origins": utils.get_allow_origin_header_value()}})
|
|
|
|
return app
|
|
|
|
|
|
app = create_app()
|
|
|
|
if __name__ == '__main__': # pragma: no cover
|
|
app.run()
|