Skip to content

Commit

Permalink
fix: email submission
Browse files Browse the repository at this point in the history
  • Loading branch information
kirinnee committed Dec 29, 2024
1 parent 5977b89 commit d592137
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
7 changes: 6 additions & 1 deletion astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
// @ts-check
import { defineConfig } from 'astro/config';
import { defineConfig, envField } from 'astro/config';
import tailwind from '@astrojs/tailwind';

import react from '@astrojs/react';

import cloudflare from '@astrojs/cloudflare';

export default defineConfig({
env: {
schema: {
BREVO_API_KEY: envField.string({ context: 'server', access: 'secret', optional: false }),
},
},
output: 'server',
integrations: [
tailwind({
Expand Down
7 changes: 4 additions & 3 deletions src/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import { defineAction, ActionError } from 'astro:actions';
import { z } from 'astro:schema';
const { env } = Astro.locals.runtime;
import { getSecret } from 'astro:env/server';

export const server = {
submitWaitlistEmail: defineAction({
input: z.object({
email: z.string().email(),
}),
handler: async ({ email }) => {
const apiKey = getSecret('BREVO_API_KEY');

const options = {
method: 'POST',
headers: {
accept: 'application/json',
'content-type': 'application/json',
'api-key': env.BREVO_API_KEY,
'api-key': apiKey,
},
body: JSON.stringify({
email,
Expand All @@ -24,7 +26,6 @@ export const server = {
const r = await fetch('https://api.brevo.com/v3/contacts', options);

if (!r.ok) {
console.log(import.meta.env.BREVO_API_KEY);
console.error(r.statusText);
console.error(r.status);
console.error(r.url);
Expand Down
3 changes: 0 additions & 3 deletions src/env.d.ts

This file was deleted.

0 comments on commit d592137

Please sign in to comment.