|
16 | 16 | echo "Using existing SSL certificates." |
17 | 17 | fi |
18 | 18 |
|
19 | | -# Set base href |
20 | | -sed -i "s|<base href=\"[^\"]*\"|<base href=\"${BASE_HREF}\"|g" /usr/share/nginx/html/index.html |
| 19 | +# Determine web root based on BASE_HREF |
| 20 | +WEB_ROOT="/usr/share/nginx/html" |
| 21 | +if [ "$BASE_HREF" != "/" ]; then |
| 22 | + # Ensure BASE_HREF starts with a single slash and does not end with a slash |
| 23 | + # Example: /bdip |
| 24 | + BASE_HREF=$(echo "$BASE_HREF" | sed 's|^\(/*\)|/|; s|/*$||') |
| 25 | + |
| 26 | + WEB_ROOT="/usr/share/nginx/html${BASE_HREF}" |
| 27 | + |
| 28 | + # Use a temporary directory to move files without including the target directory |
| 29 | + TEMP_DIR=$(mktemp -d) |
| 30 | + mv /usr/share/nginx/html/* "$TEMP_DIR" |
| 31 | + # Create the new web root directory |
| 32 | + mkdir -p "$WEB_ROOT" |
| 33 | + # Move from the temporary directory to the new web root |
| 34 | + mv "$TEMP_DIR"/* "$WEB_ROOT" |
| 35 | + # Clean up the temporary directory |
| 36 | + rmdir "$TEMP_DIR" |
| 37 | + |
| 38 | + # Update Nginx try_files directive to reflect BASE_HREF |
| 39 | + sed -i "s|try_files \$uri \$uri/ /index.html;|try_files \$uri \$uri/ ${BASE_HREF}/index.html;|g" /etc/nginx/conf.d/default.conf |
| 40 | +fi |
| 41 | + |
| 42 | +# Set base href in index.html |
| 43 | +sed -i "s|<base href=\"[^\"]*\"|<base href=\"${BASE_HREF%/}/\"|g" "$WEB_ROOT"/index.html |
21 | 44 |
|
22 | 45 | # Ensure PROXY_BASE_HREF is set, defaulting to BASE_HREF if not provided |
23 | 46 | PROXY_BASE_HREF=${PROXY_BASE_HREF:-$BASE_HREF} |
| 47 | +if [ "$PROXY_BASE_HREF" != "/" ]; then |
| 48 | + # Ensure PROXY_BASE_HREF starts and ends with a slash |
| 49 | + # Example: /bdip-proxy/ |
| 50 | + PROXY_BASE_HREF=$(echo "$PROXY_BASE_HREF" | sed 's|^\(/*\)|/|; s|/*$|/|') |
| 51 | +fi |
| 52 | +# Update Nginx configuration for proxy |
| 53 | +if [ "$PROXY_BASE_HREF" != "/" ]; then |
| 54 | + # Replace proxy_pass with upstream_endpoint |
| 55 | + sed -i "/location \/bdip-proxy\/v2\/namespaces\/pegi3s\/repositories/{ |
| 56 | + :a |
| 57 | + n |
| 58 | + /^[[:space:]]*proxy_pass/{ |
| 59 | + i\ |
| 60 | + rewrite ^$PROXY_BASE_HREF(.*)$ /\$1 break; |
| 61 | + s|proxy_pass .*;|proxy_pass \$upstream_endpoint;| |
| 62 | + b |
| 63 | + } |
| 64 | + ba |
| 65 | + }" /etc/nginx/conf.d/default.conf |
| 66 | +fi |
| 67 | +sed -i "s|/v2/namespaces/pegi3s/repositories|${PROXY_BASE_HREF}v2/namespaces/pegi3s/repositories|g" /etc/nginx/conf.d/default.conf |
24 | 68 | # Set proxy base href |
25 | | -sed -i "s|/v2/namespaces/pegi3s/repositories|${PROXY_BASE_HREF}v2/namespaces/pegi3s/repositories|g" /usr/share/nginx/html/main*.js |
| 69 | +sed -i "s|/v2/namespaces/pegi3s/repositories|${PROXY_BASE_HREF}v2/namespaces/pegi3s/repositories|g" "$WEB_ROOT"/main*.js |
26 | 70 |
|
27 | 71 | # Start nginx |
28 | 72 | echo "Starting Nginx..." |
|
0 commit comments