First Code upload

This commit is contained in:
Thomas Cole 2022-01-17 21:37:07 -05:00
parent f379a719f0
commit a3eddbc20f
4 changed files with 65 additions and 1 deletions

1
.env-sample Normal file
View File

@ -0,0 +1 @@
SECRET_KEY=""

4
.gitignore vendored
View File

@ -1 +1,3 @@
node_modules/
node_modules/
.env
package-lock.json

44
index.js Normal file
View File

@ -0,0 +1,44 @@
const express = require('express')
const crypto = require('crypto')
const bodyParser = require('body-parser')
require('dotenv').config()
const SECRET = process.env.SECRET_KEY
const app = express()
const port = 9000
const options = {
inflate: true,
limit: '100kb',
type: 'application/json',
}
app.use(bodyParser.raw(options))
app.post('/buildhook', (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(`Example app listening at http://localhost:${port}`)
})

17
package.json Normal file
View File

@ -0,0 +1,17 @@
{
"name": "expressbuild",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"dev": "nodemon index.js"
},
"author": "Thomas Cole",
"license": "MIT",
"dependencies": {
"dotenv": "^14.2.0",
"express": "^4.17.2",
"nodemon": "^2.0.15"
}
}