diff options
Diffstat (limited to 'packages/integrations/cloudflare/test/fixtures/astro-env')
10 files changed, 102 insertions, 0 deletions
diff --git a/packages/integrations/cloudflare/test/fixtures/astro-env/.dev.vars b/packages/integrations/cloudflare/test/fixtures/astro-env/.dev.vars new file mode 100644 index 000000000..3cf69c1f5 --- /dev/null +++ b/packages/integrations/cloudflare/test/fixtures/astro-env/.dev.vars @@ -0,0 +1 @@ +API_SECRET=123456789 diff --git a/packages/integrations/cloudflare/test/fixtures/astro-env/astro.config.ts b/packages/integrations/cloudflare/test/fixtures/astro-env/astro.config.ts new file mode 100644 index 000000000..b7d556b3b --- /dev/null +++ b/packages/integrations/cloudflare/test/fixtures/astro-env/astro.config.ts @@ -0,0 +1,14 @@ +import cloudflare from '@astrojs/cloudflare'; +import { defineConfig, envField } from 'astro/config'; + +export default defineConfig({ + env: { + schema: { + API_URL: envField.string({ context: 'client', access: 'public', optional: true }), + PORT: envField.number({ context: 'server', access: 'public', default: 4321 }), + API_SECRET: envField.string({ context: 'server', access: 'secret' }), + }, + }, + adapter: cloudflare(), + output: 'server', +}); diff --git a/packages/integrations/cloudflare/test/fixtures/astro-env/package.json b/packages/integrations/cloudflare/test/fixtures/astro-env/package.json new file mode 100644 index 000000000..d726e88fd --- /dev/null +++ b/packages/integrations/cloudflare/test/fixtures/astro-env/package.json @@ -0,0 +1,12 @@ +{ + "name": "@test/astro-cloudflare-astro-env", + "version": "0.0.0", + "private": true, + "dependencies": { + "@astrojs/cloudflare": "workspace:*", + "astro": "workspace:*" + }, + "devDependencies": { + "wrangler": "^4.14.1" + } +} diff --git a/packages/integrations/cloudflare/test/fixtures/astro-env/src/actions.ts b/packages/integrations/cloudflare/test/fixtures/astro-env/src/actions.ts new file mode 100644 index 000000000..79d675a37 --- /dev/null +++ b/packages/integrations/cloudflare/test/fixtures/astro-env/src/actions.ts @@ -0,0 +1,12 @@ +import { defineAction } from "astro:actions"; +import { API_SECRET } from "astro:env/server"; + +export const server = { + getSecret: defineAction({ + handler(_input, _context) { + return { + secret: API_SECRET, + }; + }, + }), +};
\ No newline at end of file diff --git a/packages/integrations/cloudflare/test/fixtures/astro-env/src/env.d.ts b/packages/integrations/cloudflare/test/fixtures/astro-env/src/env.d.ts new file mode 100644 index 000000000..60f5ec0d0 --- /dev/null +++ b/packages/integrations/cloudflare/test/fixtures/astro-env/src/env.d.ts @@ -0,0 +1,13 @@ +/// <reference path="../.astro/types.d.ts" /> +/// <reference path="../.astro/env.d.ts" /> +/// <reference types="astro/client" /> + +type Runtime = import('@astrojs/cloudflare').Runtime; + +declare namespace App { + interface Locals extends Runtime { + otherLocals: { + test: string; + }; + } +}
\ No newline at end of file diff --git a/packages/integrations/cloudflare/test/fixtures/astro-env/src/middleware.ts b/packages/integrations/cloudflare/test/fixtures/astro-env/src/middleware.ts new file mode 100644 index 000000000..e0985dc8f --- /dev/null +++ b/packages/integrations/cloudflare/test/fixtures/astro-env/src/middleware.ts @@ -0,0 +1,9 @@ +import { defineMiddleware } from 'astro/middleware' +import { API_SECRET } from 'astro:env/server' + +const secret = API_SECRET + +export const onRequest = defineMiddleware((_ctx, next) => { + console.log({ secret }) + return next() +})
\ No newline at end of file diff --git a/packages/integrations/cloudflare/test/fixtures/astro-env/src/pages/index.astro b/packages/integrations/cloudflare/test/fixtures/astro-env/src/pages/index.astro new file mode 100644 index 000000000..7e50474ed --- /dev/null +++ b/packages/integrations/cloudflare/test/fixtures/astro-env/src/pages/index.astro @@ -0,0 +1,27 @@ +--- +import { API_URL } from "astro:env/client" +import { PORT, API_SECRET } from "astro:env/server" + +const runtime = Astro.locals.runtime; +--- +<html> + <head> + <title>Astro Env</title> + </head> + <body> + <h1>Astro Env</h1> + <pre id="runtime">{JSON.stringify(runtime.env, null, 2)}</pre> + <div> + <span>API_URL</span> + <span id="client">{API_URL}</span> + </div> + <div> + <span>PORT</span> + <span id="server">{PORT}</span> + </div> + <div> + <span>API_SECRET</span> + <span id="secret">{API_SECRET}</span> + </div> + </body> +</html> diff --git a/packages/integrations/cloudflare/test/fixtures/astro-env/src/pages/test.astro b/packages/integrations/cloudflare/test/fixtures/astro-env/src/pages/test.astro new file mode 100644 index 000000000..74e4223a7 --- /dev/null +++ b/packages/integrations/cloudflare/test/fixtures/astro-env/src/pages/test.astro @@ -0,0 +1,6 @@ +--- +import { actions } from "astro:actions"; +const { data } = await Astro.callAction(actions.getSecret, {}); +--- + +<span id="secret">{data?.secret}</span>
\ No newline at end of file diff --git a/packages/integrations/cloudflare/test/fixtures/astro-env/tsconfig.json b/packages/integrations/cloudflare/test/fixtures/astro-env/tsconfig.json new file mode 100644 index 000000000..c02b48a37 --- /dev/null +++ b/packages/integrations/cloudflare/test/fixtures/astro-env/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "astro/tsconfigs/strict" +}
\ No newline at end of file diff --git a/packages/integrations/cloudflare/test/fixtures/astro-env/wrangler.toml b/packages/integrations/cloudflare/test/fixtures/astro-env/wrangler.toml new file mode 100644 index 000000000..121ab5993 --- /dev/null +++ b/packages/integrations/cloudflare/test/fixtures/astro-env/wrangler.toml @@ -0,0 +1,5 @@ +name = "astro-env" + +[vars] +API_URL = "https://google.de" +PORT = 4322 |