forked from okkays/fa-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
52 lines (41 loc) · 1.66 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
51
52
import os
import flask
from flask import request
import flask_cors
from dotenv import load_dotenv
import submit
load_dotenv()
def build_app():
# Set up the static folder to serve our angular client resources (*.js, *.css)
app = flask.Flask(__name__,
static_folder='dist/client', static_url_path='/client')
app.register_blueprint(submit.blueprint)
# If we're running in debug, defer to the typescript development server
# This gets us things like live reload and better sourcemaps.
if app.config['DEBUG']:
app.config['API_URL'] = os.getenv('DEBUG_API_URL') or 'http://localhost:5000'
app.config['ORIGIN'] = os.getenv('DEBUG_ORIGIN') or 'http://localhost:4200'
flask_cors.CORS(app,
allow_headers='*',
origins=[app.config['ORIGIN']],
supports_credentials=True)
else:
app.config['API_URL'] = os.getenv('PROD_API_URL')
# Set the secret key to enable access to session data.
app.secret_key = os.urandom(24)
# A catch-all route to serve the angular app.
# If no other routes match (such as /example) this will be called, and the
# angular app will take over routing.
@app.route('/', defaults={'path': ''})
@app.route('/<path:path>', methods=['POST', 'GET'])
def serve_angular(path):
if flask.current_app.config['DEBUG']:
target = '/'.join([
flask.current_app.config['ORIGIN'].rstrip('/'),
app.static_url_path.strip('/'),
path.lstrip('/')
])
return flask.redirect(target)
return flask.send_file('dist/client/index.html')
return app
app = build_app()