feat(thank-you): make extension APP_URL shop-aware (dev shop -> dev backend)

This commit is contained in:
Gerhard Scheikl
2026-05-09 20:52:10 +02:00
parent 884070cddc
commit 35dea965f6
@@ -2,7 +2,16 @@ import "@shopify/ui-extensions/preact";
import { render } from "preact"; import { render } from "preact";
import { useEffect, useState } from "preact/hooks"; import { useEffect, useState } from "preact/hooks";
const APP_URL = "https://invoice-app.linumiq.com"; const APP_URL_PROD = "https://invoice-app.linumiq.com";
const APP_URL_DEV = "https://invoice-app-dev.linumiq.com";
const DEV_SHOPS = new Set(["linumiq-dev.myshopify.com"]);
function resolveAppUrl(shopify: any): string {
const shop: string | undefined =
shopify?.shop?.myshopifyDomain ?? shopify?.shop?.value?.myshopifyDomain;
if (shop && DEV_SHOPS.has(shop)) return APP_URL_DEV;
return APP_URL_PROD;
}
interface PaymentInstructions { interface PaymentInstructions {
language: "de" | "en"; language: "de" | "en";
@@ -45,8 +54,9 @@ function Extension() {
return; return;
} }
const token: string = await shopify.sessionToken.get(); const token: string = await shopify.sessionToken.get();
const appUrl = resolveAppUrl(shopify);
const res = await fetch( const res = await fetch(
`${APP_URL}/api/public/payment-info?orderId=${encodeURIComponent(orderId)}`, `${appUrl}/api/public/payment-info?orderId=${encodeURIComponent(orderId)}`,
{ headers: { Authorization: `Bearer ${token}` } }, { headers: { Authorization: `Bearer ${token}` } },
); );
if (!res.ok) { if (!res.ok) {