forked from swagger-api/swagger-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-run.sh
executable file
·72 lines (60 loc) · 2.49 KB
/
docker-run.sh
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#! /bin/sh
set -e
BASE_URL=${BASE_URL:-/}
NGINX_ROOT=/usr/share/nginx/html
INDEX_FILE=$NGINX_ROOT/index.html
NGINX_CONF=/etc/nginx/nginx.conf
if [[ "${BASE_URL}" != "/" ]]; then
sed -i "s|location / {|location $BASE_URL {|g" $NGINX_CONF
fi
## Adding env var support for file passed with URL env variable
## When set, URL has priority over SWAGGER_FILE
if [[ "${URL}" ]]; then
sed -i "s|SwaggerEditorBundle({|SwaggerEditorBundle({\n url: '${URL}',|g" $INDEX_FILE
## Adding env var support for swagger file (json or yaml)
elif [[ -f "$SWAGGER_FILE" ]]; then
cp -s "$SWAGGER_FILE" "$NGINX_ROOT"
REL_PATH="/$(basename $SWAGGER_FILE)"
sed -i "s|SwaggerEditorBundle({|SwaggerEditorBundle({\n url: '$REL_PATH',|g" $INDEX_FILE
if [[ -z "$SWAGGER_ROOT" ]]; then
SWAGGER_ROOT="$(dirname $SWAGGER_FILE)"
fi
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
fi
## Adding env var support for `queryConfigEnabled` core configuration parameter of SwaggerUI
if [[ "${QUERY_CONFIG_ENABLED}" = "true" ]]; then
sed -i "s|queryConfigEnabled: false|queryConfigEnabled: true|" $INDEX_FILE
fi
if [[ "${URL_SWAGGER2_GENERATOR}" ]]; then
if [[ "$URL_SWAGGER2_GENERATOR" != "null" ]]; then
sed -i "s|SwaggerEditorBundle({|SwaggerEditorBundle({\n swagger2GeneratorUrl: '${URL_SWAGGER2_GENERATOR}',|g" $INDEX_FILE
else
sed -i "s|SwaggerEditorBundle({|SwaggerEditorBundle({\n swagger2GeneratorUrl: null,|g" $INDEX_FILE
fi
fi
if [[ "${URL_SWAGGER2_CONVERTER}" ]]; then
if [[ "$URL_SWAGGER2_CONVERTER" != "null" ]]; then
sed -i "s|SwaggerEditorBundle({|SwaggerEditorBundle({\n swagger2ConverterUrl: '${URL_SWAGGER2_CONVERTER}',|g" $INDEX_FILE
else
sed -i "s|SwaggerEditorBundle({|SwaggerEditorBundle({\n swagger2ConverterUrl: null,|g" $INDEX_FILE
fi
fi
if [[ "${URL_OAS3_GENERATOR}" ]]; then
if [[ "$URL_OAS3_GENERATOR" != "null" ]]; then
sed -i "s|SwaggerEditorBundle({|SwaggerEditorBundle({\n oas3GeneratorUrl: '${URL_OAS3_GENERATOR}',|g" $INDEX_FILE
else
sed -i "s|SwaggerEditorBundle({|SwaggerEditorBundle({\n oas3GeneratorUrl: null,|g" $INDEX_FILE
fi
fi
exec nginx -g 'daemon off;'
## Gzip after replacements
#find /usr/share/nginx/html/ -type f -regex ".*\.\(html\|js\|css\)" -exec sh -c "gzip < {} > {}.gz" \;
#
#exec nginx -g 'daemon off;'