我没有太多一起使用 Node 和 BigCommerce 的经验,这确实是我第一次尝试。我在 Amazon 的 AWS EB 上部署了 NodeJS,当我尝试在 BigCommerce 上安装我的草稿应用程序时,它卡在安装中并且进度指示器无限期地停留。
我正在使用 BigCommerce 文档中提到的 npm 包 node-bigcommerce: https://github.com/getconversio/node-bigcommerce/
目前我的配置如下:
const bigCommerce = new BigCommerce({
logLevel: "info",
clientId: "my id",
secret: "my secret",
callback: "hostname",
responseType: "json",
apiVersion: "v3" // Default is v2
});
以及我用于身份验证、加载、卸载的代码:
router.get("/auth", (req, res, next) => {
bigCommerce
.authorize(req.query)
.then(data => res.render("auth", { title: "Authorized!", data: data }))
.catch(next);
});
router.get("/load", (req, res, next) => {
try {
const data = bigCommerce.verify(req.query["signed_payload"]);
res.render("load", { title: "Welcome!", data: data });
} catch (err) {
next(err);
}
});
router.get("/uninstall", (req, res, next) => {
try {
const data = bigCommerce.verify(req.query["signed_payload"]);
res.render("uninstall", { title: "Uninstalled!", data: data });
} catch (err) {
next(err);
}
});
我也尝试过使用常规的 app.get('/', cb) ,但什么也没有。 我还看到身份验证在数据中返回以下内容:
{ title: "Authorized!", data: "<html><body>You are being <a href="https://login.bigcommerce.com/login">redirected</a>.</body></html>" }
我不太确定如何解决这个问题,并且没有太多关于将 Node 和 BC 一起使用的文档。我该如何进行?
最佳答案
想通了。有几件事,我完全忘记了在 Node 服务器上设置 HTTPS,但设置之后,加载进度覆盖终于消失了。另一个缺失的链接是我正在使用的包 https://github.com/getconversio/node-bigcommerce ,在请求 header 中,他们使用 applications/json,但这应该是“Content-Type: application/x-www-form-urlencoded”,在这对夫妇更改所有内容后,一切正常。
关于node.js - BigCommerce 和 NodeJS 应用程序 - 身份验证、加载、卸载过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49060678/