-
Notifications
You must be signed in to change notification settings - Fork 0
Proyectos #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proyectos #9
Changes from all commits
0c34ae0
a8a7ed0
0d9575e
67f9378
a02e529
3a8c673
b595d60
7335b03
51d1b48
e3755e5
cf6f465
111f623
fc6cdbf
9702a51
8c8e651
db5b97a
60b1015
ea24ea6
ebc411b
83dc33d
cdb1a05
e75f40f
4121205
f87568a
1f3dea6
4b7a3df
bab0a8b
5b70873
ea9a9ce
545cbf2
e61173a
9686f1d
753d4ba
6bad128
6aac62a
2536057
8612fe0
3192077
995ee91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| // @ts-check | ||
| import { defineConfig } from 'astro/config'; | ||
|
|
||
| import react from '@astrojs/react'; | ||
|
|
||
| // https://astro.build/config | ||
| export default defineConfig({}); | ||
| export default defineConfig({ | ||
| integrations: [react()] | ||
| }); |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,147 @@ | ||||||||||||||||||||||||||||
| export const onRequestPost: PagesFunction = async ({ request, env }) => { | ||||||||||||||||||||||||||||
| console.log('📨 Recibiendo petición de contacto...'); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||
| const contentType = request.headers.get('content-type') || ''; | ||||||||||||||||||||||||||||
| console.log('Content-Type:', contentType); | ||||||||||||||||||||||||||||
| let data: Record<string, string> = {}; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if (contentType.includes('application/json')) { | ||||||||||||||||||||||||||||
| data = await request.json(); | ||||||||||||||||||||||||||||
| console.log('✅ Datos JSON parseados'); | ||||||||||||||||||||||||||||
| } else if (contentType.includes('application/x-www-form-urlencoded')) { | ||||||||||||||||||||||||||||
| const form = await request.formData(); | ||||||||||||||||||||||||||||
| data = Object.fromEntries([...form.entries()].map(([k, v]) => [k, String(v)])); | ||||||||||||||||||||||||||||
| console.log('✅ Datos form-data parseados'); | ||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||
| console.error('❌ Content-type no soportado:', contentType); | ||||||||||||||||||||||||||||
| return new Response(JSON.stringify({ ok: false, error: 'Unsupported content type' }), { | ||||||||||||||||||||||||||||
| status: 415, | ||||||||||||||||||||||||||||
| headers: { 'content-type': 'application/json' }, | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const { nombre, email, asunto, mensaje } = data; | ||||||||||||||||||||||||||||
| console.log('Datos recibidos:', { nombre, email, asunto, mensajeLength: mensaje?.length }); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if (!nombre || !email || !asunto || !mensaje) { | ||||||||||||||||||||||||||||
| console.error('❌ Campos faltantes'); | ||||||||||||||||||||||||||||
| return new Response(JSON.stringify({ ok: false, error: 'Missing fields' }), { | ||||||||||||||||||||||||||||
| status: 400, | ||||||||||||||||||||||||||||
| headers: { 'content-type': 'application/json' }, | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // Basic email validation | ||||||||||||||||||||||||||||
| const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; | ||||||||||||||||||||||||||||
| if (!emailRegex.test(email)) { | ||||||||||||||||||||||||||||
| console.error('❌ Email inválido:', email); | ||||||||||||||||||||||||||||
| return new Response(JSON.stringify({ ok: false, error: 'Invalid email' }), { | ||||||||||||||||||||||||||||
| status: 400, | ||||||||||||||||||||||||||||
| headers: { 'content-type': 'application/json' }, | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // Validar Turnstile | ||||||||||||||||||||||||||||
| const turnstileToken = data['cf-turnstile-response']; | ||||||||||||||||||||||||||||
| if (!turnstileToken) { | ||||||||||||||||||||||||||||
| console.error('❌ Token de Turnstile faltante'); | ||||||||||||||||||||||||||||
| return new Response(JSON.stringify({ ok: false, error: 'Turnstile token missing' }), { | ||||||||||||||||||||||||||||
| status: 400, | ||||||||||||||||||||||||||||
| headers: { 'content-type': 'application/json' }, | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const ip = request.headers.get('CF-Connecting-IP'); | ||||||||||||||||||||||||||||
| const formData = new FormData(); | ||||||||||||||||||||||||||||
| formData.append('secret', env.TURNSTILE_SECRET_KEY || '1x0000000000000000000000000000000AA'); | ||||||||||||||||||||||||||||
|
Comment on lines
+56
to
+57
|
||||||||||||||||||||||||||||
| const formData = new FormData(); | |
| formData.append('secret', env.TURNSTILE_SECRET_KEY || '1x0000000000000000000000000000000AA'); | |
| if (!env.TURNSTILE_SECRET_KEY) { | |
| console.error('❌ TURNSTILE_SECRET_KEY no está configurado en el entorno'); | |
| return new Response(JSON.stringify({ ok: false, error: 'Server misconfiguration' }), { | |
| status: 500, | |
| headers: { 'content-type': 'application/json' }, | |
| }); | |
| } | |
| const formData = new FormData(); | |
| formData.append('secret', env.TURNSTILE_SECRET_KEY); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The email validation regex is basic and may not catch all invalid email formats. Consider using a more comprehensive email validation library or regex pattern that handles edge cases like multiple @ symbols, invalid domains, etc.