feat: enhance landing page, Telegram webhook, SEO suite, and cookie consent banner

This commit is contained in:
ayrisdev
2026-08-22 22:57:03 +03:00
parent 5ac5988a3a
commit 61dd85133c
26 changed files with 3264 additions and 896 deletions
+82 -14
View File
@@ -2,7 +2,7 @@ import { NextRequest, NextResponse } from 'next/server'
const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
// Basit in-memory rate limiting (MVP — production'da Redis kullan)
// Basit in-memory rate limiting
const ipRequestMap = new Map<string, { count: number; resetAt: number }>()
const RATE_LIMIT = 5 // maksimum istek
const WINDOW_MS = 60_000 // 1 dakika
@@ -22,6 +22,69 @@ function checkRateLimit(ip: string): boolean {
return true
}
function escapeHtml(str: string): string {
return str
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
}
async function sendTelegramNotification({
name,
email,
org,
phone,
ip,
}: {
name: string
email: string
org?: string | null
phone?: string | null
ip: string
}) {
const botToken = process.env.TELEGRAM_BOT_TOKEN
const chatId = process.env.TELEGRAM_CHAT_ID
if (!botToken || !chatId) {
console.warn('[AyrisLegal] Telegram bildirim ayarları eksik (TELEGRAM_BOT_TOKEN veya TELEGRAM_CHAT_ID ortam değişkeni tanımlanmamış).')
return
}
const now = new Date().toLocaleString('tr-TR', { timeZone: 'Europe/Istanbul' })
const text =
`🎯 <b>Yeni AyrisLegal Demo Talebi!</b>\n\n` +
`👤 <b>Ad Soyad:</b> ${escapeHtml(name)}\n` +
`📧 <b>E-posta:</b> <code>${escapeHtml(email)}</code>\n` +
`🏢 <b>Büro / Kurum:</b> ${org ? escapeHtml(org) : '<i>Belirtilmedi</i>'}\n` +
`📞 <b>Telefon:</b> ${phone ? `<code>${escapeHtml(phone)}</code>` : '<i>Belirtilmedi</i>'}\n` +
`🌐 <b>IP Adresi:</b> <code>${escapeHtml(ip)}</code>\n` +
`⏰ <b>Tarih & Saat:</b> ${now}`
try {
const res = await fetch(`https://api.telegram.org/bot${botToken}/sendMessage`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
chat_id: chatId,
text,
parse_mode: 'HTML',
disable_web_page_preview: true,
}),
})
if (!res.ok) {
const errText = await res.text()
console.error('[AyrisLegal] Telegram API yanıt hatası:', errText)
} else {
console.log('[AyrisLegal] ✅ Telegram bildirimi başarıyla iletildi.')
}
} catch (error) {
console.error('[AyrisLegal] Telegram gönderim hatası:', error)
}
}
export async function POST(request: NextRequest) {
try {
// IP tespiti
@@ -31,51 +94,56 @@ export async function POST(request: NextRequest) {
// Rate limit
if (!checkRateLimit(ip)) {
return NextResponse.json(
{ success: false, error: 'Çok fazla istek. Lütfen bir dakika bekleyip tekrar deneyin.' },
{ success: false, error: 'Çok fazla istek gönderildi. Lütfen bir dakika bekleyip tekrar deneyin.' },
{ status: 429 }
)
}
const body = await request.json()
const { name, email, barNo, message, _hp } = body
const { name, email, org, phone, barNo, message, _hp } = body
// Honeypot kontrolü
// Honeypot kontrolü (Bot engelleme)
if (_hp) {
// Bot — 200 döndür ama işleme
return NextResponse.json({ success: true })
}
// Zorunlu alan doğrulaması
if (!name || typeof name !== 'string' || name.trim().length < 2) {
return NextResponse.json(
{ success: false, error: 'Ad Soyad zorunludur (en az 2 karakter).' },
{ success: false, error: 'Lütfen ad ve soyadınızı belirtin (en az 2 karakter).' },
{ status: 400 }
)
}
if (!email || typeof email !== 'string' || !EMAIL_REGEX.test(email.trim())) {
return NextResponse.json(
{ success: false, error: 'Geçerli bir e-posta adresi giriniz.' },
{ success: false, error: 'Lütfen geçerli bir e-posta adresi girin.' },
{ status: 400 }
)
}
// MVP: Konsola yaz
// TODO: Resend/SendGrid veya Prisma leads tablosu eklenebilir
console.log('[AyrisLegal] 🎯 Yeni Demo Talebi:', {
timestamp: new Date().toISOString(),
const leadData = {
name: name.trim(),
email: email.trim().toLowerCase(),
barNo: barNo?.trim() || null,
message: message?.trim() || null,
org: org?.trim() || barNo?.trim() || null,
phone: phone?.trim() || message?.trim() || null,
ip,
}
// Konsol logu
console.log('[AyrisLegal] 🎯 Yeni Demo Talebi Alındı:', {
timestamp: new Date().toISOString(),
...leadData,
})
// Telegram Botuna Anlık Bildirim Gönder (Hata durumunda form akışını kesmez)
await sendTelegramNotification(leadData)
return NextResponse.json({ success: true }, { status: 200 })
} catch (err) {
console.error('[AyrisLegal] Contact API hatası:', err)
return NextResponse.json(
{ success: false, error: 'Sunucu hatası oluştu.' },
{ success: false, error: 'Sunucu hatası oluştu. Lütfen tekrar deneyin.' },
{ status: 500 }
)
}