Add Torob Product API v3 for store-module sites with a store setting to enable it.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Alireza Hassani
2026-09-03 15:26:23 +03:30
co-authored by Cursor
parent 6f1b13b6dc
commit 42cf29bc4e
28 changed files with 1080 additions and 62 deletions
+1
View File
@@ -14,6 +14,7 @@
# Scripts on the VM (same folder):
# patch-nginx-seo.sh <host> — add /sitemap.xml + /robots.txt API proxies to an existing nginx site
# patch-nginx-pay.sh <host> — add /meshkee/payments/{zarinpal|mellat}/callback API proxies
# patch-nginx-torob.sh <host> — add /torob_api/v3/products API proxy (store-module tenants)
#
# Env (.env): PORT, DEPLOY_TOKEN, ALLOWED_SLUGS
#
+58
View File
@@ -0,0 +1,58 @@
#!/usr/bin/env bash
# Insert / update the Torob Product API v3 proxy on a storefront nginx site.
# Torob POSTs https://{host}/torob_api/v3/products (JWT aud = shop host).
set -euo pipefail
HOST="${1:-}"
API_HOST="${MESHKEE_API_HOST:-api.meshkee.com}"
if [[ -z "$HOST" ]]; then
echo "usage: patch-nginx-torob.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
PATH_LOC="/torob_api/v3/products"
if grep -qF "location = ${PATH_LOC}" "$NGINX_AVAILABLE"; then
echo "already present: ${PATH_LOC}"
exit 0
fi
block="$(cat <<NGINX
location = ${PATH_LOC} {
proxy_pass https://${API_HOST}/api/v1/tenants/${HOST}/torob_api/v3/products;
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;
proxy_set_header X-Torob-Token \$http_x_torob_token;
proxy_set_header X-Torob-Token-Version \$http_x_torob_token_version;
proxy_pass_request_body on;
proxy_pass_request_headers on;
}
NGINX
)"
tmp="$(mktemp)"
awk -v block="$block" '
/location \/ \{/ && !done {
print block
done = 1
}
{ print }
' "$NGINX_AVAILABLE" >"$tmp"
mv "$tmp" "$NGINX_AVAILABLE"
echo "added: ${PATH_LOC}"
nginx -t
systemctl reload nginx
echo "patched nginx Torob product API location for $HOST"
+16
View File
@@ -252,6 +252,19 @@ PROXY_COMMON=$(cat <<PROXY
proxy_pass_request_headers on;
}
location = /torob_api/v3/products {
proxy_pass https://api.meshkee.com/api/v1/tenants/${HOST}/torob_api/v3/products;
proxy_set_header Host api.meshkee.com;
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;
proxy_set_header X-Torob-Token \$http_x_torob_token;
proxy_set_header X-Torob-Token-Version \$http_x_torob_token_version;
proxy_pass_request_body on;
proxy_pass_request_headers on;
}
location / {
proxy_pass http://127.0.0.1:${PORT};
proxy_http_version 1.1;
@@ -300,6 +313,9 @@ else
if [[ -x "$SCRIPT_DIR/patch-nginx-pay.sh" ]]; then
"$SCRIPT_DIR/patch-nginx-pay.sh" "$HOST" || true
fi
if [[ -x "$SCRIPT_DIR/patch-nginx-torob.sh" ]]; then
"$SCRIPT_DIR/patch-nginx-torob.sh" "$HOST" || true
fi
fi
# SSL is issued separately via ssl.sh / Super Admin "Issue SSL" — do not run