diff --git a/server.js b/server.js index c811e264..00e94546 100644 --- a/server.js +++ b/server.js @@ -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 ', + to: ['posimai.project@gmail.com'], + reply_to: email, + subject: `[Store お問い合わせ] ${typeLabel}`, + html: `

種別: ${typeLabel}

+

名前: ${name}

+

メール: ${email}

+ ${subject ? `

件名: ${subject}

` : ''} +

メッセージ:

+
${message}
`, + }), + }); + 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; }