2021-11-23 04:09:13 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
2022-03-09 07:08:48 +00:00
|
|
|
set -o errexit
|
|
|
|
|
set -o nounset
|
|
|
|
|
set -o pipefail
|
|
|
|
|
set -o xtrace
|
2021-11-23 04:09:13 +00:00
|
|
|
|
2022-03-09 07:08:48 +00:00
|
|
|
http_conf="/opt/appsmith/templates/nginx-app-http.conf.template.sh"
|
|
|
|
|
https_conf="/opt/appsmith/templates/nginx-app-https.conf.template.sh"
|
|
|
|
|
|
|
|
|
|
APP_TEMPLATE="$http_conf"
|
2021-11-23 05:52:09 +00:00
|
|
|
|
|
|
|
|
# Check exist certificate with given custom domain
|
2022-03-16 12:21:25 +00:00
|
|
|
if [[ -n ${APPSMITH_CUSTOM_DOMAIN:-} ]]; then
|
2022-03-09 07:08:48 +00:00
|
|
|
APP_TEMPLATE="$https_conf"
|
|
|
|
|
if ! [[ -e "/etc/letsencrypt/live/$APPSMITH_CUSTOM_DOMAIN" ]]; then
|
|
|
|
|
source "/opt/appsmith/init_ssl_cert.sh"
|
|
|
|
|
if ! init_ssl_cert "$APPSMITH_CUSTOM_DOMAIN"; then
|
|
|
|
|
echo "Status code from init_ssl_cert is $?"
|
|
|
|
|
APP_TEMPLATE="$http_conf"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
2021-11-23 04:09:13 +00:00
|
|
|
fi
|
|
|
|
|
|
2022-03-16 12:21:25 +00:00
|
|
|
bash "$APP_TEMPLATE" "${APPSMITH_CUSTOM_DOMAIN:-}" > /etc/nginx/sites-available/default
|
2021-11-23 04:09:13 +00:00
|
|
|
|
2022-03-15 08:02:59 +00:00
|
|
|
index_html_served=/opt/appsmith/editor/index.html
|
|
|
|
|
index_html_original=/opt/appsmith/index.html.original
|
|
|
|
|
if [[ ! -f $index_html_original ]]; then
|
|
|
|
|
cp -v "$index_html_served" "$index_html_original"
|
|
|
|
|
fi
|
|
|
|
|
|
2022-03-09 07:08:48 +00:00
|
|
|
node -e '
|
|
|
|
|
const fs = require("fs")
|
2022-03-15 08:02:59 +00:00
|
|
|
const content = fs.readFileSync("'"$index_html_original"'", "utf8").replace(
|
2022-03-09 07:08:48 +00:00
|
|
|
/\b__(APPSMITH_[A-Z0-9_]+)__\b/g,
|
2022-03-15 08:02:59 +00:00
|
|
|
(placeholder, name) => (process.env[name] || "")
|
2022-03-09 07:08:48 +00:00
|
|
|
)
|
2022-03-15 08:02:59 +00:00
|
|
|
fs.writeFileSync("'"$index_html_served"'", content)
|
2022-03-09 07:08:48 +00:00
|
|
|
'
|
2021-11-23 04:09:13 +00:00
|
|
|
|
2021-11-24 14:52:22 +00:00
|
|
|
exec nginx -g "daemon off;"
|