1
This commit is contained in:
34
api/gitea-webhook.js
Normal file
34
api/gitea-webhook.js
Normal file
@@ -0,0 +1,34 @@
|
||||
// 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 = 'your-project-name'; // Vercel 项目名
|
||||
const TEAM_ID = 'your-team-id-or-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' });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user