Stores synced route config from /meshkee/sitemap-config.json, serves sitemap.xml and robots.txt per tenant, and invalidates cache on CMS writes. Co-authored-by: Cursor <cursoragent@cursor.com>
62 lines
1.7 KiB
Bash
Executable File
62 lines
1.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Insert Meshkee SEO proxy locations (/sitemap.xml, /robots.txt) into an existing storefront nginx site.
|
|
set -euo pipefail
|
|
|
|
HOST="${1:-}"
|
|
API_HOST="${MESHKEE_API_HOST:-api.meshkee.com}"
|
|
|
|
if [[ -z "$HOST" ]]; then
|
|
echo "usage: patch-nginx-seo.sh <host>" >&2
|
|
exit 1
|
|
fi
|
|
|
|
NGINX_AVAILABLE="/etc/nginx/sites-available/$HOST"
|
|
|
|
if [[ ! -f "$NGINX_AVAILABLE" ]]; then
|
|
echo "missing nginx site for $HOST" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if grep -q 'location = /sitemap.xml' "$NGINX_AVAILABLE"; then
|
|
echo "nginx SEO locations already present for $HOST"
|
|
exit 0
|
|
fi
|
|
|
|
TMP="$(mktemp)"
|
|
SEO_BLOCK="$(cat <<NGINX
|
|
location = /sitemap.xml {
|
|
proxy_pass https://${API_HOST}/api/v1/tenants/${HOST}/sitemap.xml;
|
|
proxy_set_header Host ${API_HOST};
|
|
proxy_ssl_server_name on;
|
|
proxy_set_header X-Real-IP \$remote_addr;
|
|
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto \$scheme;
|
|
add_header Cache-Control "public, max-age=900";
|
|
}
|
|
|
|
location = /robots.txt {
|
|
proxy_pass https://${API_HOST}/api/v1/tenants/${HOST}/robots.txt;
|
|
proxy_set_header Host ${API_HOST};
|
|
proxy_ssl_server_name on;
|
|
proxy_set_header X-Real-IP \$remote_addr;
|
|
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto \$scheme;
|
|
add_header Cache-Control "public, max-age=900";
|
|
}
|
|
|
|
NGINX
|
|
)"
|
|
|
|
awk -v block="$SEO_BLOCK" '
|
|
/location \/ \{/ && !done {
|
|
print block
|
|
done = 1
|
|
}
|
|
{ print }
|
|
' "$NGINX_AVAILABLE" >"$TMP"
|
|
|
|
mv "$TMP" "$NGINX_AVAILABLE"
|
|
nginx -t
|
|
systemctl reload nginx
|
|
echo "patched nginx SEO locations for $HOST"
|