- Forward X-Site-Host from Astro to the bridge so loopback calls use the public domain JSON - Normalize newsproject.bitreport.pt.json (categories slug/label, wp on 127.0.0.1:8080) - Degrade homepage/trending when WordPress is down instead of 500 - Extend webhook-deploy.sh for config/ and wordpress/ changes; add deploy-hook-server + systemd unit - Document automatic Gitea webhook flow in docs/deployment.md; align DOMAINS_CONFIG_PATH env Co-Authored-By: Paperclip <[email protected]> Made-with: Cursor
68 lines
1.9 KiB
JavaScript
68 lines
1.9 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Minimal HTTP hook for Gitea push → pull/build on the LXC.
|
|
* Listen on loopback only; Gitea reaches the host via VPN/firewall or Actions runner.
|
|
*
|
|
* Env:
|
|
* DEPLOY_HOOK_HOST default 127.0.0.1
|
|
* DEPLOY_HOOK_PORT default 9090
|
|
* DEPLOY_HOOK_TOKEN required — send as Authorization: Bearer <token> or X-Deploy-Token
|
|
* DEPLOY_SCRIPT default /opt/news-platform/deploy/scripts/webhook-deploy.sh
|
|
*/
|
|
import http from 'node:http';
|
|
import { spawn } from 'node:child_process';
|
|
|
|
const HOST = process.env.DEPLOY_HOOK_HOST ?? '127.0.0.1';
|
|
const PORT = parseInt(process.env.DEPLOY_HOOK_PORT ?? '9090', 10);
|
|
const TOKEN = process.env.DEPLOY_HOOK_TOKEN ?? '';
|
|
const SCRIPT = process.env.DEPLOY_SCRIPT ?? '/opt/news-platform/deploy/scripts/webhook-deploy.sh';
|
|
|
|
function unauthorized(res) {
|
|
res.writeHead(401, { 'Content-Type': 'text/plain; charset=utf-8' });
|
|
res.end('Unauthorized');
|
|
}
|
|
|
|
function extract_token(req) {
|
|
const auth = req.headers.authorization ?? '';
|
|
if (auth.startsWith('Bearer ')) {
|
|
return auth.slice(7).trim();
|
|
}
|
|
const h = req.headers['x-deploy-token'];
|
|
return typeof h === 'string' ? h.trim() : '';
|
|
}
|
|
|
|
const server = http.createServer((req, res) => {
|
|
if (req.method !== 'POST' || req.url !== '/hook') {
|
|
res.writeHead(404).end();
|
|
return;
|
|
}
|
|
|
|
if (!TOKEN) {
|
|
res.writeHead(503, { 'Content-Type': 'text/plain; charset=utf-8' });
|
|
res.end('DEPLOY_HOOK_TOKEN not set');
|
|
return;
|
|
}
|
|
|
|
const token = extract_token(req);
|
|
if (token !== TOKEN) {
|
|
unauthorized(res);
|
|
return;
|
|
}
|
|
|
|
req.resume();
|
|
|
|
const child = spawn('/bin/bash', [SCRIPT], {
|
|
detached: true,
|
|
stdio: 'ignore',
|
|
env: { ...process.env, PATH: process.env.PATH ?? '/usr/bin:/bin' },
|
|
});
|
|
child.unref();
|
|
|
|
res.writeHead(202, { 'Content-Type': 'text/plain; charset=utf-8' });
|
|
res.end('Accepted');
|
|
});
|
|
|
|
server.listen(PORT, HOST, () => {
|
|
process.stdout.write(`news-platform deploy hook on http://${HOST}:${PORT}/hook\n`);
|
|
});
|