const http = require('http'); const { execFile } = require('child_process'); const crypto = require('crypto'); const PORT = 9000; const SECRET = 'meeting-proto-deploy-secret'; const server = http.createServer((req, res) => { if (req.method !== 'POST' || req.url !== '/deploy') { res.writeHead(404); res.end('Not found'); return; } let body = ''; req.on('data', chunk => { body += chunk; }); req.on('end', () => { // Verify Gitea signature const sig = req.headers['x-gitea-signature']; if (sig) { const hmac = crypto.createHmac('sha256', SECRET).update(body).digest('hex'); if (sig !== hmac) { console.log(`${new Date().toISOString()} - Invalid signature, rejecting`); res.writeHead(403); res.end('Invalid signature'); return; } } console.log(`${new Date().toISOString()} - Deploy triggered`); res.writeHead(200); res.end('Deploy started'); execFile('bash', ['D:/meeting-protocol-service/deploy.sh'], (err, stdout, stderr) => { if (err) { console.error(`Deploy error: ${err.message}`); return; } console.log(`Deploy output: ${stdout}`); }); }); }); server.listen(PORT, () => { console.log(`Webhook server listening on port ${PORT}`); });