feat(thank-you): make extension APP_URL shop-aware (dev shop -> dev backend)
This commit is contained in:
@@ -2,7 +2,16 @@ import "@shopify/ui-extensions/preact";
|
||||
import { render } from "preact";
|
||||
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 {
|
||||
language: "de" | "en";
|
||||
@@ -45,8 +54,9 @@ function Extension() {
|
||||
return;
|
||||
}
|
||||
const token: string = await shopify.sessionToken.get();
|
||||
const appUrl = resolveAppUrl(shopify);
|
||||
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}` } },
|
||||
);
|
||||
if (!res.ok) {
|
||||
|
||||
Reference in New Issue
Block a user