Skip to content

Commit

Permalink
refactor: replace env with astro:env
Browse files Browse the repository at this point in the history
  • Loading branch information
nblackburn committed Dec 5, 2024
1 parent 5a898ff commit 2706770
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
20 changes: 11 additions & 9 deletions astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import vue from '@astrojs/vue';
import sitemap from '@astrojs/sitemap';
import { defineConfig } from 'astro/config';
import vercel from '@astrojs/vercel';
import sitemap from '@astrojs/sitemap';
import { defineConfig, envField } from 'astro/config';
import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin';

export default defineConfig({
Expand All @@ -19,13 +19,15 @@ export default defineConfig({
}
}),

vite: {
plugins: [vanillaExtractPlugin()],

define: {
'import.meta.env.PUBLIC_VERCEL_ANALYTICS_ID': JSON.stringify(
process.env.VERCEL_ANALYTICS_ID
)
env: {
schema: {
RESEND_API_KEY: envField({ context: 'server', access: 'secret' }),
TURNSTILE_SITE_KEY: envField({ context: 'client', access: 'public' }),
TURNSTILE_SECRET_KEY: envField({ context: 'server', access: 'secret' })
}
},

vite: {
plugins: [vanillaExtractPlugin()]
}
});
3 changes: 2 additions & 1 deletion src/components/turnStile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

<script lang="ts">
import * as styles from './turnStile.css';
import { TURNSTILE_SITE_KEY } from 'astro:env/server';
import { defineComponent, onMounted, ref } from 'vue';
export default defineComponent({
emits: ['callback', 'error', 'expired', 'unsupported'],
setup(_props, ctx) {
const element = ref();
const siteKey = import.meta.env.PUBLIC_TURNSTILE_SITE_KEY;
const siteKey = TURNSTILE_SITE_KEY;
const setupScript = () => {
const turnStile = window.turnstile;
Expand Down
5 changes: 3 additions & 2 deletions src/pages/api/contact.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import config from '@root/src/config';
import type { APIRoute } from 'astro';
import { RESEND_API_KEY, TURNSTILE_SECRET_KEY } from 'astro:env/server';

const resendApikey = import.meta.env.RESEND_API_KEY;
const turnstyleSecretKey = import.meta.env.TURNSTILE_SECRET_KEY;
const resendApikey = RESEND_API_KEY;
const turnstyleSecretKey = TURNSTILE_SECRET_KEY;

export const runtime = 'edge';
export const prerender = false;
Expand Down

0 comments on commit 2706770

Please sign in to comment.