From 704c42c404be599c65cb954a7c1d8295091e8e00 Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Fri, 23 Feb 2024 20:32:24 +0000 Subject: [PATCH] Use a catchall for single page apps. (#763) This creates a new environment variable, CERC_SINGLE_PAGE_APP, which controls whether a catchall redirection back to / is applied. If the value is not explicitly set, we try to detect if the page looks like a single-page app. Reviewed-on: https://git.vdb.to/cerc-io/stack-orchestrator/pulls/763 Co-authored-by: Thomas E Lackey Co-committed-by: Thomas E Lackey --- .../scripts/start-serving-app.sh | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/stack_orchestrator/data/container-build/cerc-webapp-base/scripts/start-serving-app.sh b/stack_orchestrator/data/container-build/cerc-webapp-base/scripts/start-serving-app.sh index f9aa2c33..4fa1dc03 100755 --- a/stack_orchestrator/data/container-build/cerc-webapp-base/scripts/start-serving-app.sh +++ b/stack_orchestrator/data/container-build/cerc-webapp-base/scripts/start-serving-app.sh @@ -3,13 +3,28 @@ if [ -n "$CERC_SCRIPT_DEBUG" ]; then set -x fi +CERC_LISTEN_PORT=${CERC_LISTEN_PORT:-80} CERC_WEBAPP_FILES_DIR="${CERC_WEBAPP_FILES_DIR:-/data}" CERC_ENABLE_CORS="${CERC_ENABLE_CORS:-false}" +CERC_SINGLE_PAGE_APP="${CERC_SINGLE_PAGE_APP}" + +if [ -z "${CERC_SINGLE_PAGE_APP}" ]; then + if [ 1 -eq $(find "${CERC_WEBAPP_FILES_DIR}" -name '*.html' | wc -l) ] && [ -d "${CERC_WEBAPP_FILES_DIR}/static" ]; then + CERC_SINGLE_PAGE_APP=true + else + CERC_SINGLE_PAGE_APP=false + fi +fi if [ "true" == "$CERC_ENABLE_CORS" ]; then CERC_HTTP_EXTRA_ARGS="$CERC_HTTP_EXTRA_ARGS --cors" fi +if [ "true" == "$CERC_SINGLE_PAGE_APP" ]; then + # Create a catchall redirect back to / + CERC_HTTP_EXTRA_ARGS="$CERC_HTTP_EXTRA_ARGS --proxy http://localhost:${CERC_LISTEN_PORT}?" +fi + LACONIC_HOSTED_CONFIG_FILE=${LACONIC_HOSTED_CONFIG_FILE} if [ -z "${LACONIC_HOSTED_CONFIG_FILE}" ]; then if [ -f "/config/laconic-hosted-config.yml" ]; then @@ -20,8 +35,8 @@ if [ -z "${LACONIC_HOSTED_CONFIG_FILE}" ]; then fi if [ -f "${LACONIC_HOSTED_CONFIG_FILE}" ]; then - /scripts/apply-webapp-config.sh $LACONIC_HOSTED_CONFIG_FILE ${CERC_WEBAPP_FILES_DIR} + /scripts/apply-webapp-config.sh $LACONIC_HOSTED_CONFIG_FILE "${CERC_WEBAPP_FILES_DIR}" fi /scripts/apply-runtime-env.sh ${CERC_WEBAPP_FILES_DIR} -http-server $CERC_HTTP_EXTRA_ARGS -p ${CERC_LISTEN_PORT:-80} ${CERC_WEBAPP_FILES_DIR} +http-server $CERC_HTTP_EXTRA_ARGS -p ${CERC_LISTEN_PORT} "${CERC_WEBAPP_FILES_DIR}" \ No newline at end of file