File size: 904 Bytes
74626f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Flask Application Initialization
Sets up the Flask app with necessary configurations
"""

from flask import Flask, send_from_directory
from flask_cors import CORS
import os

# Initialize Flask app
# Serves static files from the build directory (../dist)
app = Flask(__name__, static_folder='../dist', static_url_path='')

# Enable CORS
CORS(app)

# Serve React App (Catch-all route)
@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def serve(path):
    # Don't interfere with API routes
    if path.startswith('api'):
        return {"error": "Not found"}, 404
        
    if path != "" and os.path.exists(os.path.join(app.static_folder, path)):
        return send_from_directory(app.static_folder, path)
    
    # Return index.html for SPA routing
    return send_from_directory(app.static_folder, 'index.html')

# Flag to indicate if database was just created
DBcreated = False