express - 带有 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 应用程序的哪个位置以使其工作
解决方案
我可以让它工作的唯一方法是在同一台服务器上创建另一个应用程序(我使用 express),然后在该服务器上使用一个端点作为 github webhook,然后我从那里运行部署脚本。
简单的解决方案,希望这可以帮助某人..
推荐阅读
- spring-boot - 春季配置服务器未发布到rabbitmq
- java - 具有多个私有最终字段的测试配置类
- azure-storage - Azure 存储模拟器无法初始化并显示“数据库 'AzureStorageEmulatorDb57' 不存在”
- jquery - 如何将输入文本放入数组
- powershell - 更新 Windows 共享上的 Unix 权限
- python - ValueError:float() 的无效文字:
- c++ - 无法访问私有成员..但成员被明确声明为公共
- python - 在 A[i] 之前的 100 万个项目中,有几个比 A[i] 小?
- go - 如何按名称获取结构的属性?
- java - 输出有问题