feat(store): お問い合わせフォームを Resend API に切り替え(Formspree 廃止)

This commit is contained in:
posimai 2026-04-21 19:52:53 +09:00
parent 100064693d
commit b00e31cb90
1 changed files with 53 additions and 0 deletions

View File

@ -3203,6 +3203,59 @@ ${excerpt}
req2.end();
});
// POST /store/contact — posimai-store お問い合わせフォーム
r.post('/store/contact', async (req, res) => {
const { name, email, type, subject, message } = req.body || {};
if (!name || !email || !message) {
return res.status(400).json({ error: 'name, email, message は必須です' });
}
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
return res.status(400).json({ error: 'メールアドレスの形式が不正です' });
}
if (!process.env.RESEND_API_KEY) {
console.error('[store/contact] RESEND_API_KEY が未設定');
return res.status(503).json({ error: 'メール送信が設定されていません' });
}
const typeLabel = {
purchase: '購入・決済について',
license: 'ライセンス・アクセス権について',
refund: '返金について',
usage: '使い方・機能について',
bug: '不具合の報告',
other: 'その他',
}[type] || type || '(未選択)';
try {
const emailRes = await fetch('https://api.resend.com/emails', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.RESEND_API_KEY}`,
},
body: JSON.stringify({
from: 'Posimai Store <hello@soar-enrich.com>',
to: ['posimai.project@gmail.com'],
reply_to: email,
subject: `[Store お問い合わせ] ${typeLabel}`,
html: `<p><strong>種別:</strong> ${typeLabel}</p>
<p><strong>名前:</strong> ${name}</p>
<p><strong>メール:</strong> ${email}</p>
${subject ? `<p><strong>件名:</strong> ${subject}</p>` : ''}
<p><strong>メッセージ:</strong></p>
<pre style="white-space:pre-wrap">${message}</pre>`,
}),
});
if (!emailRes.ok) {
const errBody = await emailRes.text();
console.error('[store/contact] Resend error:', emailRes.status, errBody);
return res.status(500).json({ error: 'メール送信に失敗しました' });
}
res.json({ ok: true });
} catch (e) {
console.error('[store/contact] fetch error:', e.message);
res.status(500).json({ error: 'Internal server error' });
}
});
return r;
}