|
|
@ -12,8 +12,12 @@ const GITEA_SECRET = "123"; |
|
|
|
// Serve static files from the 'public' directory
|
|
|
|
app.use(express.static(path.join(__dirname, 'public'))); |
|
|
|
|
|
|
|
// Middleware to parse JSON payloads
|
|
|
|
app.use(bodyParser.json()); |
|
|
|
// Middleware to capture raw body
|
|
|
|
app.use(bodyParser.json({ |
|
|
|
verify: (req, res, buf, encoding) => { |
|
|
|
req.rawBody = buf.toString(encoding || 'utf8'); |
|
|
|
} |
|
|
|
})); |
|
|
|
|
|
|
|
// Custom middleware to handle URLs without .html for specific routes
|
|
|
|
app.use((req, res, next) => { |
|
|
@ -54,7 +58,7 @@ app.get('/articles/:articleName', (req, res) => { |
|
|
|
// Webhook handler
|
|
|
|
app.post('/api', (req, res) => { |
|
|
|
const signature = req.headers['x-gitea-signature']; |
|
|
|
const payload = JSON.stringify(req.body); |
|
|
|
const payload = req.rawBody; |
|
|
|
|
|
|
|
if (!signature || !payload) { |
|
|
|
return res.status(400).send('Invalid payload or missing signature'); |
|
|
@ -66,6 +70,8 @@ app.post('/api', (req, res) => { |
|
|
|
|
|
|
|
console.log('Signature from Gitea:', signature); |
|
|
|
console.log('Computed digest:', digest); |
|
|
|
console.log('Payload:', payload); |
|
|
|
console.log('Secret:', GITEA_SECRET); |
|
|
|
|
|
|
|
const bufferSignature = Buffer.from(signature, 'hex'); |
|
|
|
const bufferDigest = Buffer.from(digest, 'hex'); |
|
|
|