How to write a webhook in gitea in node.js / javascript

Below is an example written using node.js

const express = require('express')
const crypto = require('crypto')
const bodyParser = require('body-parser')
const SECRET = 'HELLO_SECRET'

const port = 9000
const app = express()

const options = {
    inflate: true,
    limit: '100kb',
    type: 'application/json',
}
app.use(bodyParser.raw(options))

app.get('/', (req, res) => res.send('git-hooks'))

app.post('/', (req, res) => {
    const signature = req.headers['x-gitea-signature']
    if (!signature) {
        console.error('x-gitea-signature missing')
        return res.send()
    }

    const hmac = crypto.createHmac('sha256', SECRET)
    hmac.update(req.body)

    const payload_signature = hmac.digest('hex')
    if (signature !== payload_signature) {
        console.error('signature !== payload_signature')
        return res.send()
    }

    const json = JSON.parse(req.body.toString())
    console.log('json')
    console.log(json)
    
    // SIGNATURES MATCHES, do your thing here.
    
    res.send('success')
})

app.listen(port, () => console.log(`git-hooks app running on ${port}`))