38 lines
920 B
Python
38 lines
920 B
Python
import os
|
|
from flask import Flask
|
|
from flask_cors import CORS
|
|
from src.api.routes import api_bp
|
|
from flask_sse import sse
|
|
from config import config
|
|
|
|
|
|
def create_app():
|
|
app = Flask(__name__)
|
|
|
|
origins = [
|
|
"http://localhost:3000",
|
|
"http://127.0.0.1:3000"
|
|
]
|
|
CORS(app, supports_credentials=True, origins=origins)
|
|
|
|
env = os.environ.get('FLASK_ENV', 'default')
|
|
|
|
if env == "production":
|
|
app.config.update(SESSION_COOKIE_SAMESITE="None", SESSION_COOKIE_SECURE=True)
|
|
else:
|
|
app.config.update(SESSION_COOKIE_SAMESITE="Lax", SESSION_COOKIE_SECURE=False)
|
|
|
|
app.config.from_object(config[env])
|
|
|
|
app.register_blueprint(sse, url_prefix='/stream')
|
|
app.register_blueprint(api_bp, url_prefix='/api')
|
|
|
|
return app
|
|
|
|
|
|
if __name__ == "__main__":
|
|
port = int(os.environ.get("PORT", 5000))
|
|
|
|
app = create_app()
|
|
app.run(host='0.0.0.0', port=port, debug=True)
|