Auto detect whether using `yarn watch` or `yarn build`
+import sys, os
from flask import redirect
+import optparse
from . import api
from .app import Flask
@@ -11,10 +13,24 @@ from pathlib import Path
def create_app(test_config=None):
# Setup static resources
# create and configure the app
+ # auto detect for yarn watch or yarn build
+ static_dir_watch = '/js'
+ static_dir_build = '/static'
+ if 'js' in os.listdir(GUI_PUBLIC_DIR):
+ # using yarn watch
+ static_dir = static_dir_watch
+ else:
+ static_dir = static_dir_build
+
+ # if os.environ.get('FLASK_ENV') == 'production':
+ # static_dir = static_dir_build
+ # else:
+ # static_dir = static_dir_watch
+ print('using static_dir:', static_dir)
app = Flask(__name__,
instance_relative_config=True,
- static_folder=GUI_STATIC_DIR,
- static_url_path='/js')
+ static_folder=GUI_PUBLIC_DIR + static_dir,
+ static_url_path=static_dir)
app.config.from_mapping(
SECRET_KEY='dev'
