File size: 879 Bytes
5008b66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""Application factory for the voice cloning backend."""

import os
from flask import Flask
from flask_cors import CORS


def create_app():
    """Create and configure the Flask application."""

    app = Flask(__name__)
    
    # CORS configuration - allow specific frontend URL or all origins
    allowed_origins = os.getenv('FRONTEND_URL', '*').split(',')
    cors_config = {
        "origins": allowed_origins if allowed_origins != ['*'] else '*',
        "methods": ["GET", "POST", "DELETE", "OPTIONS"],
        "allow_headers": ["Content-Type", "Authorization"]
    }
    CORS(app, resources={r"/api/*": cors_config})

    from .routes import bp

    app.register_blueprint(bp)
    
    # Root endpoint
    @app.route('/')
    def index():
        return {'message': 'Voice Cloning API', 'status': 'running', 'api_prefix': '/api'}
    
    return app


app = create_app()