mirror of
https://github.com/Kizuren/kizuren.dev.git
synced 2025-12-21 21:16:12 +01:00
Implement everything
This commit is contained in:
parent
d966dd9562
commit
30d747e046
26 changed files with 1069 additions and 6 deletions
35
server/api/send-contact.post.js
Normal file
35
server/api/send-contact.post.js
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
const body = await readBody(event)
|
||||
const { message } = body
|
||||
|
||||
const webhookUrl = process.env.DISCORD_WEBHOOK
|
||||
|
||||
if (!webhookUrl) {
|
||||
throw new Error('Discord webhook URL is not configured')
|
||||
}
|
||||
|
||||
const response = await fetch(webhookUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(message)
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text()
|
||||
throw new Error(`Discord API error: ${response.status} - ${errorText}`)
|
||||
}
|
||||
|
||||
return { success: true }
|
||||
} catch (error) {
|
||||
console.error('Failed to send message to Discord:', error)
|
||||
|
||||
return createError({
|
||||
statusCode: 500,
|
||||
statusMessage: 'Failed to send message',
|
||||
message: error.message || 'An unknown error occurred'
|
||||
})
|
||||
}
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue