From 3b28d1c52d9ddedb8d3ee0a20f8a8de552c4bcd2 Mon Sep 17 00:00:00 2001 From: Richard Bergsma Date: Sun, 2 Nov 2025 02:06:29 +0100 Subject: [PATCH] Integrate dotenv for environment variable management and enhance form error handling - Added dotenv to load environment variables from a .env file in server.js for better configuration management. - Improved the Form component by refining error handling during form submission, including specific messages for different error scenarios. - Updated the CSRF token handling and ensured proper validation of response types from the contact API. - Enhanced user feedback by providing clearer messages for success and error states in the form submission process. --- server.js | 4 ++ src/components/ui/Form.astro | 103 ++++++++++++++++++++++++++------- src/utils/email-handler.ts | 52 ++++++++++++++--- src/utils/gemini-spam-check.ts | 2 +- 4 files changed, 129 insertions(+), 32 deletions(-) diff --git a/server.js b/server.js index b0edcc6..21b7db2 100644 --- a/server.js +++ b/server.js @@ -1,3 +1,7 @@ +// Load environment variables from .env file first +import dotenv from 'dotenv'; +dotenv.config(); + import express from 'express'; import compression from 'compression'; import { handler } from './dist/server/entry.mjs'; diff --git a/src/components/ui/Form.astro b/src/components/ui/Form.astro index b8324d8..160c848 100644 --- a/src/components/ui/Form.astro +++ b/src/components/ui/Form.astro @@ -84,12 +84,12 @@ const { inputs, textarea, disclaimer, button = 'Contact us', description = '', s { disclaimer && (
-
+
@@ -163,13 +163,10 @@ const { inputs, textarea, disclaimer, button = 'Contact us', description = '', s
-