首页 > 解决方案 > 带有 NextJs 的 Github webhook

问题描述

我正在开发一个 NextJS 项目,我想使用 github webhook 来部署具有部署说明的脚本。

我在 github 中设置了一个推送 webhook

我尝试在我的 server.ts 文件中添加以下代码,现在使用 ngrok 进行测试

// testing
server.post("/webhooks/github", function(req, res) {
  var sender = req.body.sender;
  var branch = req.body.ref;

  if (branch.indexOf("master") > -1 && sender.login === githubUsername) {
    deploy(res);
  }
});

function deploy(res: any) {
  childProcess.exec("sh deploy.sh", function(err, stdout, stderr) {
    if (err) {
      console.error(err, stderr);
      return res.send(500);
    }
    console.log(stdout);
    res.send(200);
  });
}

这个文件是我的 nextJS 应用程序的节点文件

但是我在我的 ngrok 日志中得到了 502

我想知道我应该将这个 webhook 端点放在我的 NextJS 应用程序的哪个位置以使其工作

标签: expressgithubnext.js

解决方案


我可以让它工作的唯一方法是在同一台服务器上创建另一个应用程序(我使用 express),然后在该服务器上使用一个端点作为 github webhook,然后我从那里运行部署脚本。

简单的解决方案,希望这可以帮助某人..


推荐阅读