@bridge-ai-dev/ecom-chat 1.0.11 → 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bridge-ai-dev/ecom-chat",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "description": "Bridge E-commerce Chat widget integration for Next.js with Litium authentication",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -12,19 +12,20 @@ const CREATE_CART_MUTATION = `
12
12
 
13
13
  /**
14
14
  * Constructs the GraphQL endpoint URL.
15
- * Uses the same Next.js server so the rewrite rule in next.config.js
16
- * forwards the request to Litium with proper context.
17
- *
18
- * Note: The incoming request.url may show https:// (from the proxy),
19
- * but the Next.js dev server runs on http://. We force http:// for
20
- * localhost to avoid SSL errors.
15
+ * In some strict Next.js setups, local HTTP fetch is rejected ("host contains HTTP protocol").
16
+ * To avoid this, we prioritize the RUNTIME_LITIUM_SERVER_URL if available,
17
+ * falling back to the incoming request origin.
21
18
  */
22
19
  function getGraphQLUrl(request: NextRequest): string {
23
- const url = new URL(request.url);
24
- // Force http:// for localhost — Next.js dev server doesn't use SSL
25
- if (url.hostname === 'localhost' || url.hostname === '127.0.0.1') {
26
- url.protocol = 'http:';
20
+ const litiumServerUrl = process.env.RUNTIME_LITIUM_SERVER_URL;
21
+ if (litiumServerUrl) {
22
+ // Ensure no trailing slash
23
+ const baseUrl = litiumServerUrl.endsWith('/') ? litiumServerUrl.slice(0, -1) : litiumServerUrl;
24
+ return `${baseUrl}/storefront.graphql`;
27
25
  }
26
+
27
+ // Fallback if env var is missing
28
+ const url = new URL(request.url);
28
29
  return `${url.origin}/storefront.graphql`;
29
30
  }
30
31