diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index b44e96b..5ce14cf 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -73,9 +73,10 @@ jobs: echo "API Gateway URL: ${API_GATEWAY_URL}" echo "API Key: ${API_KEY}" - echo "API_GATEWAY_URL=${API_GATEWAY_URL}" > ../.env.production - echo "API_KEY=${API_KEY}" >> ../.env.production - cat ../.env.production + echo "NEXT_PUBLIC_API_GATEWAY_URL=${API_GATEWAY_URL}" > ../.env.production + echo "NEXT_PUBLIC_API_KEY=${API_KEY}" >> ../.env.production + + # 5. Build and Package Next.js - name: Build and Package Next.js diff --git a/src/components/Contact/index.tsx b/src/components/Contact/index.tsx index 7f61259..2ebfe4c 100644 --- a/src/components/Contact/index.tsx +++ b/src/components/Contact/index.tsx @@ -1,6 +1,6 @@ 'use client' -// Test: +// Test: // curl -X POST -H "Content-Type: application/json" \ // -d '{"name": "Test", "email": "test@example.com", "message": "Hello"}' \ // https://mkz66v3npa.execute-api.ap-southeast-2.amazonaws.com/prod/contact @@ -21,17 +21,27 @@ export default function ContactPage() { const [submitStatus, setSubmitStatus] = useState<'idle' | 'loading' | 'success' | 'error'>('idle') const [errorMessage, setErrorMessage] = useState('') + const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setSubmitStatus('loading') console.log('Form submitted with data:', formData) try { - const response = await fetch('/api/contact', { + // Use environment variables if available, otherwise use /api/contact + const endpoint = process.env.NEXT_PUBLIC_API_GATEWAY_URL || '/api/contact' + const headers: Record = { + 'Content-Type': 'application/json', + } + + // Add API key if available + if (process.env.NEXT_PUBLIC_API_KEY) { + headers['x-api-key'] = process.env.NEXT_PUBLIC_API_KEY + } + + const response = await fetch(endpoint, { method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, + headers, body: JSON.stringify(formData) }) @@ -65,7 +75,7 @@ export default function ContactPage() { {/* Left Column - Header & Contact Info */}
{/* Hero Text */} -

Get in Touch

- +61 2 6176 1580 - @@ -176,10 +186,10 @@ export default function ContactPage() {