Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 

66 рядки
1.6 KiB

  1. #! /bin/sh
  2. set -e
  3. BASE_URL=${BASE_URL:-/}
  4. NGINX_ROOT=/usr/share/nginx/html
  5. INDEX_FILE=$NGINX_ROOT/index.html
  6. NGINX_CONF=/etc/nginx/nginx.conf
  7. node /usr/share/nginx/configurator $INDEX_FILE
  8. replace_in_index () {
  9. if [ "$1" != "**None**" ]; then
  10. sed -i "s|/\*||g" $INDEX_FILE
  11. sed -i "s|\*/||g" $INDEX_FILE
  12. sed -i "s|$1|$2|g" $INDEX_FILE
  13. fi
  14. }
  15. replace_or_delete_in_index () {
  16. if [ -z "$2" ]; then
  17. sed -i "/$1/d" $INDEX_FILE
  18. else
  19. replace_in_index $1 $2
  20. fi
  21. }
  22. if [[ "${BASE_URL}" != "/" ]]; then
  23. sed -i "s|location / {|location $BASE_URL {|g" $NGINX_CONF
  24. fi
  25. replace_in_index myApiKeyXXXX123456789 $API_KEY
  26. if [ "$SWAGGER_JSON_URL" ]; then
  27. sed -i "s|https://petstore.swagger.io/v2/swagger.json|$SWAGGER_JSON_URL|g" $INDEX_FILE
  28. sed -i "s|http://example.com/api|$SWAGGER_JSON_URL|g" $INDEX_FILE
  29. fi
  30. if [[ -f "$SWAGGER_JSON" ]]; then
  31. REL_PATH="./$(basename $SWAGGER_JSON)"
  32. if [[ -z "$SWAGGER_ROOT" ]]; then
  33. SWAGGER_ROOT="$(dirname $SWAGGER_JSON)"
  34. fi
  35. if [[ "$BASE_URL" != "/" ]]
  36. then
  37. BASE_URL=$(echo $BASE_URL | sed 's/\/$//')
  38. sed -i \
  39. "s|#SWAGGER_ROOT|rewrite ^$BASE_URL(/.*)$ \$1 break;\n #SWAGGER_ROOT|" \
  40. $NGINX_CONF
  41. fi
  42. sed -i "s|#SWAGGER_ROOT|root $SWAGGER_ROOT/;|g" $NGINX_CONF
  43. sed -i "s|https://petstore.swagger.io/v2/swagger.json|$REL_PATH|g" $INDEX_FILE
  44. sed -i "s|http://example.com/api|$REL_PATH|g" $INDEX_FILE
  45. fi
  46. # replace the PORT that nginx listens on if PORT is supplied
  47. if [[ -n "${PORT}" ]]; then
  48. sed -i "s|8080|${PORT}|g" $NGINX_CONF
  49. fi
  50. find $NGINX_ROOT -type f -regex ".*\.\(html\|js\|css\)" -exec sh -c "gzip < {} > {}.gz" \;
  51. exec nginx -g 'daemon off;'