Rinze/src/routes/ask-form/+server.js

29 lines
621 B
JavaScript
Raw Normal View History

2022-12-17 10:37:41 +00:00
import { json as json$1 } from '@sveltejs/kit';
2021-05-15 07:44:17 +00:00
// Public webhook URL for forms.
let webhookUrl = "https://n8n.nanao.moe/webhook/fd943cbe-fd27-47f8-98ec-01c14b5104fe";
2022-07-24 16:25:35 +00:00
export async function POST({ body }) {
2021-05-15 07:44:17 +00:00
if (!body.message) {
2022-12-17 10:37:41 +00:00
return json$1({
error: "No message!"
}, {
status: 400
})
2021-05-15 07:44:17 +00:00
}
const data = await fetch(webhookUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
message: body.message ?? "Blank form",
}),
})
2022-12-17 10:37:41 +00:00
return json$1({
success: true,
})
2021-05-15 07:44:17 +00:00
}