首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何连接React和Shopify应用程序?

如何连接React和Shopify应用程序?
EN

Stack Overflow用户
提问于 2017-11-01 10:40:31
回答 1查看 792关注 0票数 0

我是shopify-App developmet的新手,我遇到了Polaris,Shopify为一致的用户界面开发提供了react库。我的想法是构建一个Node.js快速应用程序来验证和安装应用程序,并处理数据,并为商店管理的用户界面提供一个反应应用程序。

我在网上搜索,但找不到一种标准或推荐的方式将react应用程序连接到shopify应用程序。

我能弄清楚的是,当商店管理员从Apps部分选择应用程序时,从Node应用程序重定向到React应用程序,并且成功地通过了下面的验证。

代码语言:javascript
复制
app.get('/shopify/callback', (req, res) => {
  const { shop, hmac, code, state } = req.query;
  const stateCookie = cookie.parse(req.headers.cookie).state;

  if (state !== stateCookie) {
    return res.status(403).send('Request origin cannot be verified');
  }

  if (shop && hmac && code) {
    const map = Object.assign({}, req.query);
    delete map['signature'];
    delete map['hmac'];
    const message = querystring.stringify(map);
    const generatedHash = crypto
      .createHmac('sha256', apiSecret)
      .update(message)
      .digest('hex');

    if (generatedHash !== hmac) {
      return res.status(400).send('HMAC validation failed');
    }

    const accessTokenRequestUrl = 'https://' + shop + '/admin/oauth/access_token';
    const accessTokenPayload = {
      client_id: apiKey,
      client_secret: apiSecret,
      code,
    };

    request.post(accessTokenRequestUrl, { json: accessTokenPayload })
      .then((accessTokenResponse) => {
        const accessToken = accessTokenResponse.access_token;

        const shopRequestUrl = 'https://' + shop + '/admin/shop.json';
        const shopRequestHeaders = {
          'X-Shopify-Access-Token': accessToken,
        };
        res.redirect([URL to the react app built with Polaris]);
      })
      .catch((error) => {
        res.status(error.statusCode).send(error.error.error_description);
      });

  } else {
    res.status(400).send('Required parameters missing');
  }
});

我做到了,但我不确定这是否是推荐的方法。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-11-03 10:37:38

它们是三种不同的东西: Node.JS、React和Polaris,您可以选择其中的任何一种。Polaris是一个库,如果您想使用它,只需运行yarn add @shopify-polaris并阅读它的文档。就这样。

无论有没有北极星,您仍然可以创建一个Shopify应用程序,与各种堆栈。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47052986

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档