我是shopify-App developmet的新手,我遇到了Polaris,Shopify为一致的用户界面开发提供了react库。我的想法是构建一个Node.js快速应用程序来验证和安装应用程序,并处理数据,并为商店管理的用户界面提供一个反应应用程序。
我在网上搜索,但找不到一种标准或推荐的方式将react应用程序连接到shopify应用程序。
我能弄清楚的是,当商店管理员从Apps部分选择应用程序时,从Node应用程序重定向到React应用程序,并且成功地通过了下面的验证。
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');
}
});我做到了,但我不确定这是否是推荐的方法。
发布于 2017-11-03 10:37:38
它们是三种不同的东西: Node.JS、React和Polaris,您可以选择其中的任何一种。Polaris是一个库,如果您想使用它,只需运行yarn add @shopify-polaris并阅读它的文档。就这样。
无论有没有北极星,您仍然可以创建一个Shopify应用程序,与各种堆栈。
https://stackoverflow.com/questions/47052986
复制相似问题