-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
50 lines (38 loc) · 1.06 KB
/
app.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import sys
from flask import Flask, jsonify, request
from flask_cors import CORS
app = Flask(__name__)
app_config = {"host": "0.0.0.0", "port": sys.argv[1]}
"""
---------------------- DEVELOPER MODE CONFIG -----------------------
"""
# Developer mode uses app.py
if "app.py" in sys.argv[0]:
# Update app config
app_config["debug"] = True
# CORS settings
cors = CORS(
app,
resources={r"/*": {"origins": "http://localhost*"}},
)
# CORS headers
app.config["CORS_HEADERS"] = "Content-Type"
"""
--------------------------- REST CALLS -----------------------------
"""
# Remove and replace with your own
@app.route("/example")
def example():
# See /src/components/App.js for frontend call
return jsonify("Example response from Flask! Learn more in /app.py & /src/components/App.js")
"""
-------------------------- APP SERVICES ----------------------------
"""
# Quits Flask on Electron exit
@app.route("/quit")
def quit():
shutdown = request.environ.get("werkzeug.server.shutdown")
shutdown()
return
if __name__ == "__main__":
app.run(**app_config)