From bec0533d5c1f5c05cdd66ddc7824419954267b2b Mon Sep 17 00:00:00 2001 From: Wesley Schwengle Date: Mon, 15 Jun 2020 21:04:28 -0400 Subject: [PATCH] Fix(Docker): case where SWAGGER_ROOT in conjunction with BASE_URL does not work (#6147) --- docker/run.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/docker/run.sh b/docker/run.sh index b2c01645..2ab717f0 100644 --- a/docker/run.sh +++ b/docker/run.sh @@ -24,7 +24,7 @@ replace_or_delete_in_index () { fi } -if [ "${BASE_URL}" ]; then +if [[ "${BASE_URL}" != "/" ]]; then sed -i "s|location / {|location $BASE_URL {|g" $NGINX_CONF fi @@ -36,14 +36,20 @@ if [ "$SWAGGER_JSON_URL" ]; then fi if [[ -f "$SWAGGER_JSON" ]]; then - cp -s "$SWAGGER_JSON" "$NGINX_ROOT" REL_PATH="./$(basename $SWAGGER_JSON)" if [[ -z "$SWAGGER_ROOT" ]]; then SWAGGER_ROOT="$(dirname $SWAGGER_JSON)" fi - sed -i "s|#SWAGGER_ROOT|root $SWAGGER_ROOT;|g" $NGINX_CONF + if [[ "$BASE_URL" != "/" ]] + then + BASE_URL=$(echo $BASE_URL | sed 's/\/$//') + sed -i \ + "s|#SWAGGER_ROOT|rewrite ^$BASE_URL(/.*)$ \$1 break;\n #SWAGGER_ROOT|" \ + $NGINX_CONF + fi + sed -i "s|#SWAGGER_ROOT|root $SWAGGER_ROOT/;|g" $NGINX_CONF sed -i "s|https://petstore.swagger.io/v2/swagger.json|$REL_PATH|g" $INDEX_FILE sed -i "s|http://example.com/api|$REL_PATH|g" $INDEX_FILE