Skip to content

Commit bec0533

Browse files
authoredJun 16, 2020
Fix(Docker): case where SWAGGER_ROOT in conjunction with BASE_URL does not work (#6147)
1 parent eeb0b73 commit bec0533

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed
 

‎docker/run.sh

+9-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ replace_or_delete_in_index () {
2424
fi
2525
}
2626

27-
if [ "${BASE_URL}" ]; then
27+
if [[ "${BASE_URL}" != "/" ]]; then
2828
sed -i "s|location / {|location $BASE_URL {|g" $NGINX_CONF
2929
fi
3030

@@ -36,14 +36,20 @@ if [ "$SWAGGER_JSON_URL" ]; then
3636
fi
3737

3838
if [[ -f "$SWAGGER_JSON" ]]; then
39-
cp -s "$SWAGGER_JSON" "$NGINX_ROOT"
4039
REL_PATH="./$(basename $SWAGGER_JSON)"
4140

4241
if [[ -z "$SWAGGER_ROOT" ]]; then
4342
SWAGGER_ROOT="$(dirname $SWAGGER_JSON)"
4443
fi
4544

46-
sed -i "s|#SWAGGER_ROOT|root $SWAGGER_ROOT;|g" $NGINX_CONF
45+
if [[ "$BASE_URL" != "/" ]]
46+
then
47+
BASE_URL=$(echo $BASE_URL | sed 's/\/$//')
48+
sed -i \
49+
"s|#SWAGGER_ROOT|rewrite ^$BASE_URL(/.*)$ \$1 break;\n #SWAGGER_ROOT|" \
50+
$NGINX_CONF
51+
fi
52+
sed -i "s|#SWAGGER_ROOT|root $SWAGGER_ROOT/;|g" $NGINX_CONF
4753

4854
sed -i "s|https://petstore.swagger.io/v2/swagger.json|$REL_PATH|g" $INDEX_FILE
4955
sed -i "s|http://example.com/api|$REL_PATH|g" $INDEX_FILE

0 commit comments

Comments
 (0)
Please sign in to comment.