35 lines
1.2 KiB
JavaScript
35 lines
1.2 KiB
JavaScript
// 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' });
|
||
}
|
||
}
|