import express from 'express'; import cors from 'cors'; import { DiscordWebhook } from './discord-webhook.js'; import { messageSchema } from './schemas.js'; /** * * @param {DiscordWebhook} discordWebhook * @returns {express.Express} */ export function createApp(discordWebhook) { const app = express(); app.disable('x-powered-by'); app.use(express.json()); app.use(cors()); app.post('/submit', async (req, res) => { const result = messageSchema.safeParse(req.body); if (!result.success) { res.status(400).send(result.error.message); return; } const sent = await discordWebhook.sendEmbed(result.data); if (!sent) { res.status(500).send('Tu mensaje no se ha podido guardar'); return; } res.status(201).send('va'); }); return app; }