Was it just about the content-type?!
This commit is contained in:
@@ -33,7 +33,7 @@
|
||||
const toggleFocus = () => inputInFocus = !inputInFocus
|
||||
|
||||
// Handle form submission
|
||||
async function handleForm (event: SubmitEvent) {
|
||||
async function handleForm (event: Event | HTMLFormElement) {
|
||||
const data = new FormData(this)
|
||||
const email = data.get('email')
|
||||
console.log('form:', data, email)
|
||||
@@ -41,9 +41,10 @@
|
||||
if (email) {
|
||||
const req = await fetch(this.action, {
|
||||
method: 'POST',
|
||||
headers: { 'content-type': 'application/json' },
|
||||
body: JSON.stringify({ email })
|
||||
})
|
||||
const result: FormStatus = await req.text()
|
||||
const result: FormStatus = await req.json()
|
||||
formStatus = result
|
||||
|
||||
// If successful
|
||||
|
||||
@@ -19,15 +19,14 @@ export const POST = (async ({ request, fetch }) => {
|
||||
// Newsletter API request
|
||||
const req = await fetch(`https://emailoctopus.com/api/1.6/lists/${NEWSLETTER_LIST_ID}/contacts`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
headers: { 'content-type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
api_key: NEWSLETTER_API_TOKEN,
|
||||
email_address: email,
|
||||
})
|
||||
})
|
||||
const res = await req.text()
|
||||
const res = await req.json()
|
||||
console.log('server:', res)
|
||||
return new Response(res)
|
||||
|
||||
// Other error
|
||||
if (res && res.status !== 'PENDING') {
|
||||
|
||||
Reference in New Issue
Block a user