Files
Cookies/api/gitea-webhook.js
2025-04-17 21:50:29 +08:00

35 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// api/gitea-webhook.js
import axios from 'axios';
export default async function handler(req, res) {
if (req.method !== 'POST') {
return res.status(405).send('Only POST requests allowed');
}
// 可选校验 Gitea 签名等
console.log('🔔 Received Gitea webhook');
const VERCEL_TOKEN = process.env.VERCEL_TOKEN;
const PROJECT_NAME = 'cookies'; // Vercel 项目名
const TEAM_ID = 'null'; // 如果是团队项目,写 team id否则 null
try {
const result = await axios.post('https://api.vercel.com/v13/deployments', {
name: PROJECT_NAME,
target: 'production'
}, {
headers: {
Authorization: `Bearer ${VERCEL_TOKEN}`,
'Content-Type': 'application/json'
},
params: TEAM_ID ? { teamId: TEAM_ID } : {}
});
console.log('✅ Deploy triggered:', result.data.url);
res.status(200).json({ message: 'Deploy triggered', url: result.data.url });
} catch (err) {
console.error('❌ Error triggering deploy:', err.response?.data || err.message);
res.status(500).json({ error: 'Failed to trigger deploy' });
}
}