You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Shopify Admin API在谷歌托管服务器失效,本地运行正常求排查

回答

Hey there, let's break down what's happening here and fix this issue:

First, that ENOTFOUND error means your Firebase Functions environment can't resolve the tinyrabbithole.myshopify.com domain. This is almost always a network/DNS problem, since your local setup works fine (so your API keys, permissions, and code logic are good).

Here are the steps to troubleshoot and fix this:

1. Check if your Firebase Function has outbound internet access

By default, first-gen Firebase HTTP functions can access the public internet, but if you've set up a VPC connector or restricted network settings, that could block access to Shopify's servers.

  • Head to your Firebase Console > Functions > Your getData function > Check the "Network" tab. If you're using a VPC connector, make sure it's configured to allow internet access (look for the "Internet access" toggle).
  • If you're using second-gen functions, double-check your network configuration to ensure outbound traffic isn't restricted.

2. Force a public DNS server for domain resolution

Firebase's default DNS might be having trouble resolving Shopify's domain. Let's override it with a reliable public DNS (like Google's 8.8.8.8) in your code:

const functions = require('firebase-functions');
const admin = require('firebase-admin');
const dns = require('dns');
const Shopify = require('shopify-api-node');

// Set public DNS servers to bypass potential resolution issues
dns.setServers(['8.8.8.8', '8.8.4.4']);

admin.initializeApp();

const shopify = new Shopify({
  shopName: 'tinyrabbithole',
  apiKey: 'your-api-key',
  password: 'your-app-password'
});

shopify.on('callLimits', limits => console.log(limits));

exports.getData = functions.https.onRequest((req, res) => {
  // First test DNS resolution to confirm
  dns.resolve('tinyrabbithole.myshopify.com', (dnsErr, addresses) => {
    if (dnsErr) {
      console.log('DNS failed:', dnsErr);
      return res.status(500).send('Failed to resolve Shopify domain');
    }
    console.log('Resolved Shopify IPs:', addresses);

    // Proceed with fetching orders
    shopify.order.list({ limit: 5 })
      .then(orders => {
        console.log('Fetched orders:', orders);
        return res.status(200).send(orders);
      })
      .catch(apiErr => {
        console.log('API error:', apiErr);
        return res.status(500).send(apiErr.message);
      });
  });
});

3. Use environment variables for sensitive data (best practice)

While this won't fix the current error, hardcoding your API keys and app password is risky. Let's move them to Firebase environment variables:

  • Run these commands in your terminal:
    firebase functions:config:set shopify.shop_name="tinyrabbithole" shopify.api_key="your-real-api-key" shopify.app_password="your-real-app-password"
    
  • Update your code to read these variables:
    const config = functions.config();
    const shopify = new Shopify({
      shopName: config.shopify.shop_name,
      apiKey: config.shopify.api_key,
      password: config.shopify.app_password
    });
    

4. Try deploying to a different Firebase region

Sometimes DNS issues are region-specific. Deploy your function to a different region (like us-central1) to test:

firebase deploy --only functions:getData --region us-central1

5. Test with a raw HTTP request (bypass the Shopify library)

To rule out issues with the shopify-api-node library, try making a direct request using got or axios:

const functions = require('firebase-functions');
const got = require('got');

exports.testShopifyRequest = functions.https.onRequest((req, res) => {
  const shopDomain = 'tinyrabbithole.myshopify.com';
  const apiKey = 'your-api-key';
  const appPassword = 'your-app-password';
  const authHeader = `Basic ${Buffer.from(`${apiKey}:${appPassword}`).toString('base64')}`;

  got(`https://${shopDomain}/admin/orders.json?limit=5`, {
    headers: { Authorization: authHeader }
  })
  .then(response => {
    res.status(200).send(JSON.parse(response.body));
  })
  .catch(err => {
    console.log('Raw request error:', err);
    res.status(500).send(err.message);
  });
});

If this raw request works, the issue is likely with the shopify-api-node library's configuration in the Firebase environment.


内容的提问来源于stack exchange,提问作者phongyewtong

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 07:29:31