From 944d27025f69701ed3b2112b8dc1e6b77f7c8995 Mon Sep 17 00:00:00 2001 From: Alex Frantz Date: Tue, 9 Jul 2024 20:16:00 -0400 Subject: [PATCH] account for rate limits, add dynamic url --- .env.example | 1 + .gitignore | 1 + src/components/ContactForm.tsx | 10 +++++++--- 3 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..3477fdd --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +VITE_API_BASE_URL="http://localhost:3001/v4" \ No newline at end of file diff --git a/.gitignore b/.gitignore index a547bf3..438657a 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ node_modules dist dist-ssr *.local +.env # Editor directories and files .vscode/* diff --git a/src/components/ContactForm.tsx b/src/components/ContactForm.tsx index e023781..100cc7a 100644 --- a/src/components/ContactForm.tsx +++ b/src/components/ContactForm.tsx @@ -22,7 +22,7 @@ export default function ContactForm() { } else { console.log("Form submitted") - fetch("https://api.alexav.gg/v4/contact", { + fetch(import.meta.env.VITE_API_BASE_URL + "/contact", { method: "post", headers: { 'content-type': 'application/json' @@ -32,7 +32,11 @@ export default function ContactForm() { if (res.ok) { setSuccess(true) } else { - setError("An error occurred while submitting your info.") + if (res.status === 429) { + setError("Too many tries! Try again later") + } else { + setError("An error occurred while submitting your info.") + } } }).catch((e) => { console.error(e) @@ -50,7 +54,7 @@ export default function ContactForm() { setTimeout(() => { setSuccess(false) }, 6000) - }) + }, [success]); return (