First Code upload
This commit is contained in:
parent
f379a719f0
commit
a3eddbc20f
1
.env-sample
Normal file
1
.env-sample
Normal file
@ -0,0 +1 @@
|
|||||||
|
SECRET_KEY=""
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -1 +1,3 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
|
.env
|
||||||
|
package-lock.json
|
44
index.js
Normal file
44
index.js
Normal 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
17
package.json
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user