node.js - BigCommerce 和 NodeJS 应用程序 - 身份验证、加载、卸载过程

标签 node.js bigcommerce

我没有太多一起使用 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/

相关文章:

node.js - 主机名不工作node.js

javascript - 因为我不能在顶层运行 await,我必须把它放到一个异步函数中——为什么我可以直接调用那个异步函数?

php - Bigcommerce getProducts 限制

bigcommerce - 如何在没有 Bigcommerce 白金级别的情况下启用 Google Trusted Stores

html - 将Google Analytics(分析)跟踪添加到BigCommerce App Store列表中

javascript - Node.js 通过带有传递参数的 shell 脚本执行 python 脚本

node.js - include 语句对性能的影响有多大?

javascript - Protractor 中的过滤器函数的 promise 是如何得到解决的?

javascript - 无法在 owl-carousel 选项数组中写入 var 值

javascript - 替换 href http ://with//的脚本