Skip to content

Commit

Permalink
frontend,scripts:Additional configuration of nginx from env vars (#1978)
Browse files Browse the repository at this point in the history
Co-authored-by: Peter Baus <[email protected]>
Co-authored-by: Samuel Pull <[email protected]>
  • Loading branch information
3 people authored Sep 20, 2024
1 parent fb85ebf commit 226b89d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
28 changes: 24 additions & 4 deletions frontend/configureServer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,35 @@ rm /etc/nginx/conf.d/default-ssl.conf

# add the proxy pass and store the conf into the nginx conf directory
sed -i -e "/# pathToApi/i\\
proxy_pass $api_protocol://$api_host:$api_port;" /etc/nginx/conf.d/default.conf
proxy_pass $api_protocol://$api_host:$api_port;" /etc/nginx/conf.d/default.conf
# Loop through each line of the multi-line string and use sed to inject it
echo "$REACT_APP_API_SERVICE_ADDITIONAL_NGINX_CONF" | while IFS= read -r line; do
sed -i -e "/# pathToApi/i\\
$line" /etc/nginx/conf.d/default.conf
done

if [ "$REACT_APP_EXPORT_SERVICE_ENABLED" = true ]; then
echo "Excel export has been enabled"
echo "$export_protocol://$export_host:$export_port/"
sed -i -e "/# pathToExcelExport/i\\
proxy_pass $export_protocol://$export_host:$export_port/;" /etc/nginx/conf.d/default.conf
proxy_pass $export_protocol://$export_host:$export_port/;" /etc/nginx/conf.d/default.conf
# Loop through each line of the multi-line string and use sed to inject it
echo "$REACT_APP_EXPORT_SERVICE_ADDITIONAL_NGINX_CONF" | while IFS= read -r line; do
sed -i -e "/# pathToExcelExport/i\\
$line" /etc/nginx/conf.d/default.conf
done
fi

if [ "$REACT_APP_EMAIL_SERVICE_ENABLED" = true ]; then
echo "Email service has been enabled"
echo "$email_protocol://$email_host:$email_port/"
sed -i -e "/# pathToEmailService/i\\
proxy_pass $email_protocol://$email_host:$email_port/;" /etc/nginx/conf.d/default.conf
proxy_pass $email_protocol://$email_host:$email_port/;" /etc/nginx/conf.d/default.conf
# Loop through each line of the multi-line string and use sed to inject it
echo "$REACT_APP_EMAIL_SERVICE_ADDITIONAL_NGINX_CONF" | while IFS= read -r line; do
sed -i -e "/# pathToEmailService/i\\
$line" /etc/nginx/conf.d/default.conf
done
fi

if [[ ! -z "${REACT_APP_EXCHANGE_RATE_URL}" ]]; then
Expand All @@ -102,7 +117,12 @@ fi


sed -i -e "/# pathToStorageService/i\\
proxy_pass $storage_service_protocol://$storage_service_host:$storage_service_port/download;" /etc/nginx/conf.d/default.conf
proxy_pass $storage_service_protocol://$storage_service_host:$storage_service_port/download;" /etc/nginx/conf.d/default.conf
# Loop through each line of the multi-line string and use sed to inject it
echo "$REACT_APP_STORAGE_SERVICE_ADDITIONAL_NGINX_CONF" | while IFS= read -r line; do
sed -i -e "/# pathToStorageService/i\\
$line" /etc/nginx/conf.d/default.conf
done

sed -i -e "s/^\(\s*include \/etc\/nginx\/sites-enabled\)/#&/" /etc/nginx/nginx.conf

Expand Down
4 changes: 4 additions & 0 deletions frontend/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
| REACT_APP_AUTHPROXY_URL | `http://localhost:4000/signin` | auth proxy ingress. Required if REACT_APP_AUTHPROXY_ENABLED is set to true |
| REACT_APP_APPLICATIONINSIGHTS_CONNECTION_STRING | _undefined_ | Azure Application Insights Connection String |
| REACT_APP_POLLING_INTERVAL | 5000 | How often is data fetched from the server, in milliseconds. We recommend setting to 30000 (30 seconds), maybe longer if you experience performance issues. |
| REACT_APP_API_SERVICE_ADDITIONAL_NGINX_CONF | _undefined_ | Additional configuration of nginx server for api service. It could be a muti-line string. It will be injected to the nginx configuration. |
| REACT_APP_EMAIL_SERVICE_ADDITIONAL_NGINX_CONF | _undefined_ | Additional configuration of nginx server for email service. It could be a muti-line string. It will be injected to the nginx configuration. |
| REACT_APP_EXPORT_SERVICE_ADDITIONAL_NGINX_CONF | _undefined_ | Additional configuration of nginx server for excel export service. It could be a muti-line string. It will be injected to the nginx configuration. |
| REACT_APP_STORAGE_SERVICE_ADDITIONAL_NGINX_CONF | _undefined_ | Additional configuration of nginx server for storage service. It could be a muti-line string. It will be injected to the nginx configuration. |

### Email-Service

Expand Down
5 changes: 5 additions & 0 deletions scripts/operation/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ REACT_APP_LOGGING_SERVICE_HOST_SSL=false
REACT_APP_LOGGING_PUSH_INTERVAL=20
REACT_APP_APPLICATIONINSIGHTS_CONNECTION_STRING=
REACT_APP_POLLING_INTERVAL=30000
# could be a multi-line set of configuration for all variables ending "_ADDITIONAL_NGINX_CONF"
REACT_APP_API_SERVICE_ADDITIONAL_NGINX_CONF=""
REACT_APP_EMAIL_SERVICE_ADDITIONAL_NGINX_CONF=""
REACT_APP_EXPORT_SERVICE_ADDITIONAL_NGINX_CONF=""
REACT_APP_STORAGE_SERVICE_ADDITIONAL_NGINX_CONF=""

## excel-export
ACCESS_CONTROL_ALLOW_ORIGIN=*
Expand Down
4 changes: 4 additions & 0 deletions scripts/operation/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ services:
REACT_APP_EXCHANGE_RATE_URL: ${REACT_APP_EXCHANGE_RATE_URL}
REACT_APP_APPLICATIONINSIGHTS_CONNECTION_STRING: ${REACT_APP_APPLICATIONINSIGHTS_CONNECTION_STRING}
REACT_APP_POLLING_INTERVAL: ${REACT_APP_POLLING_INTERVAL}
REACT_APP_API_SERVICE_ADDITIONAL_NGINX_CONF: ${REACT_APP_API_SERVICE_ADDITIONAL_NGINX_CONF}
REACT_APP_EMAIL_SERVICE_ADDITIONAL_NGINX_CONF: ${REACT_APP_EMAIL_SERVICE_ADDITIONAL_NGINX_CONF}
REACT_APP_EXPORT_SERVICE_ADDITIONAL_NGINX_CONF: ${REACT_APP_EXPORT_SERVICE_ADDITIONAL_NGINX_CONF}
REACT_APP_STORAGE_SERVICE_ADDITIONAL_NGINX_CONF: ${REACT_APP_STORAGE_SERVICE_ADDITIONAL_NGINX_CONF}
networks:
mynetwork:
ipv4_address: 172.21.0.91
Expand Down

0 comments on commit 226b89d

Please sign in to comment.