From 1e68d79ecd35af54ba96c40bb31e8d51c8a5ad87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A7=89?= Date: Thu, 28 Sep 2023 16:06:38 +0800 Subject: [PATCH] =?UTF-8?q?webhook=20=E8=87=AA=E5=8A=A8pull?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/index.js b/index.js index e2b98da..e061d8c 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,6 @@ import express from 'express' import expressWs from 'express-ws' +import { exec } from 'child_process' const app = express() const wsInstance = expressWs(app) @@ -47,4 +48,13 @@ app.ws('/webrtc/:channel', (ws, req) => { }) }) +// WEBHOOK 处理 GitHub 事件 +app.post('/webhook', (req, res) => { + console.log('WEBHOOK:', req.body) + return exec('git pull;npm i', (err, stdout, stderr) => { + if (err) return res.status(500).json({ error: err }) + return res.json({ stdout, stderr }) + }) +}) + app.listen(4096, () => console.log('Server started on port 4096'))