feat: prefer SALEOR_API_URL env var over stored auth URL

- NormalizingAPL now checks for SALEOR_API_URL env var
- If set, uses env var URL for API calls while keeping stored token
- Enables internal K8s networking without reinstallation
- Makes app portable across different network configurations

The app stores auth data during installation, but at runtime uses
SALEOR_API_URL for API calls. This allows deployment with internal
networking (e.g., http://saleor-api.saleor:8000) while keeping the
same token from installation.
This commit is contained in:
Unchained
2026-03-27 06:18:39 +02:00
parent 33fb9a8452
commit debb1365b5
+25 -2
View File
@@ -3,7 +3,9 @@ import { SaleorApp } from "@saleor/app-sdk/saleor-app";
import { FileAPL } from "@saleor/app-sdk/APL/file";
/**
* APL wrapper that normalizes HTTP to HTTPS for auth data lookups
* APL wrapper that:
* 1. Normalizes HTTP to HTTPS for auth data lookups (for Cloudflare compatibility)
* 2. Prefers SALEOR_API_URL env var over stored auth URL (for internal networking)
*/
class NormalizingAPL implements APL {
private apl: FileAPL;
@@ -16,10 +18,31 @@ class NormalizingAPL implements APL {
return url.replace(/^http:\/\//, "https://");
}
/**
* Get auth data and optionally override saleorApiUrl with env var
*/
async get(saleorApiUrl: string): Promise<AuthData | undefined> {
const normalizedUrl = this.normalizeUrl(saleorApiUrl);
console.log(`[NormalizingAPL] Looking up auth for: ${saleorApiUrl} -> ${normalizedUrl}`);
return this.apl.get(normalizedUrl);
const authData = await this.apl.get(normalizedUrl);
if (!authData) {
return undefined;
}
// If SALEOR_API_URL is set, prefer it over the stored URL
// This enables internal networking (e.g., http://saleor-api.saleor:8000)
// while still using the stored token for authentication
if (process.env.SALEOR_API_URL) {
console.log(`[NormalizingAPL] Using SALEOR_API_URL: ${process.env.SALEOR_API_URL} (env var overrides stored: ${authData.saleorApiUrl})`);
return {
...authData,
saleorApiUrl: process.env.SALEOR_API_URL,
};
}
return authData;
}
async set(authData: AuthData): Promise<void> {