Spaces:
Running
Running
Upload main.py
Browse files
main.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import sys
|
3 |
+
# DON'T CHANGE THIS !!!
|
4 |
+
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
|
5 |
+
|
6 |
+
from flask import Flask, send_from_directory
|
7 |
+
from flask_cors import CORS
|
8 |
+
from src.models.user import db
|
9 |
+
from src.routes.user import user_bp
|
10 |
+
from src.routes.post import post_bp
|
11 |
+
|
12 |
+
app = Flask(__name__, static_folder=os.path.join(os.path.dirname(__file__), 'static'))
|
13 |
+
app.config['SECRET_KEY'] = 'asdf#FGSgvasgf$5$WGT'
|
14 |
+
|
15 |
+
# Enable CORS for all routes
|
16 |
+
CORS(app)
|
17 |
+
|
18 |
+
app.register_blueprint(user_bp, url_prefix='/api')
|
19 |
+
app.register_blueprint(post_bp, url_prefix='/api')
|
20 |
+
|
21 |
+
# uncomment if you need to use database
|
22 |
+
app.config['SQLALCHEMY_DATABASE_URI'] = f"sqlite:///{os.path.join(os.path.dirname(__file__), 'database', 'app.db')}"
|
23 |
+
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
24 |
+
db.init_app(app)
|
25 |
+
with app.app_context():
|
26 |
+
db.create_all()
|
27 |
+
|
28 |
+
@app.route('/', defaults={'path': ''})
|
29 |
+
@app.route('/<path:path>')
|
30 |
+
def serve(path):
|
31 |
+
static_folder_path = app.static_folder
|
32 |
+
if static_folder_path is None:
|
33 |
+
return "Static folder not configured", 404
|
34 |
+
|
35 |
+
if path != "" and os.path.exists(os.path.join(static_folder_path, path)):
|
36 |
+
return send_from_directory(static_folder_path, path)
|
37 |
+
else:
|
38 |
+
index_path = os.path.join(static_folder_path, 'index.html')
|
39 |
+
if os.path.exists(index_path):
|
40 |
+
return send_from_directory(static_folder_path, 'index.html')
|
41 |
+
else:
|
42 |
+
return "index.html not found", 404
|
43 |
+
|
44 |
+
|
45 |
+
if __name__ == '__main__':
|
46 |
+
app.run(host='0.0.0.0', port=5001, debug=True)
|