change
This commit is contained in:
12
server.js
12
server.js
@@ -12,8 +12,12 @@ const GITEA_SECRET = "123";
|
|||||||
// Serve static files from the 'public' directory
|
// Serve static files from the 'public' directory
|
||||||
app.use(express.static(path.join(__dirname, 'public')));
|
app.use(express.static(path.join(__dirname, 'public')));
|
||||||
|
|
||||||
// Middleware to parse JSON payloads
|
// Middleware to capture raw body
|
||||||
app.use(bodyParser.json());
|
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
|
// Custom middleware to handle URLs without .html for specific routes
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
@@ -54,7 +58,7 @@ app.get('/articles/:articleName', (req, res) => {
|
|||||||
// Webhook handler
|
// Webhook handler
|
||||||
app.post('/api', (req, res) => {
|
app.post('/api', (req, res) => {
|
||||||
const signature = req.headers['x-gitea-signature'];
|
const signature = req.headers['x-gitea-signature'];
|
||||||
const payload = JSON.stringify(req.body);
|
const payload = req.rawBody;
|
||||||
|
|
||||||
if (!signature || !payload) {
|
if (!signature || !payload) {
|
||||||
return res.status(400).send('Invalid payload or missing signature');
|
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('Signature from Gitea:', signature);
|
||||||
console.log('Computed digest:', digest);
|
console.log('Computed digest:', digest);
|
||||||
|
console.log('Payload:', payload);
|
||||||
|
console.log('Secret:', GITEA_SECRET);
|
||||||
|
|
||||||
const bufferSignature = Buffer.from(signature, 'hex');
|
const bufferSignature = Buffer.from(signature, 'hex');
|
||||||
const bufferDigest = Buffer.from(digest, 'hex');
|
const bufferDigest = Buffer.from(digest, 'hex');
|
||||||
|
|||||||
Reference in New Issue
Block a user