diff --git a/.gitignore b/.gitignore
index 6240da8..f97c380 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
# build output
dist/
+worker/
# generated types
.astro/
diff --git a/astro.config.mjs b/astro.config.mjs
index f08a738..d794684 100644
--- a/astro.config.mjs
+++ b/astro.config.mjs
@@ -5,13 +5,26 @@ import prefetch from '@astrojs/prefetch';
import cloudflare from '@astrojs/cloudflare';
+const isWorker = process.argv.includes('--worker');
+
// https://astro.build/config
-export default defineConfig({
- integrations: [tailwind(), react(), prefetch()],
- output: 'hybrid',
- experimental: {
- hybridOutput: true,
- assets: true,
- },
- adapter: cloudflare(),
-});
+export default defineConfig(
+ isWorker
+ ? {
+ output: 'hybrid',
+ adapter: cloudflare({
+ mode: 'advanced',
+ }),
+ outDir: 'worker',
+ srcDir: 'cloudflare',
+ experimental: {
+ hybridOutput: true,
+ },
+ }
+ : {
+ integrations: [tailwind(), react(), prefetch()],
+ experimental: {
+ assets: true,
+ },
+ }
+);
diff --git a/build/_routes.json b/build/_routes.json
new file mode 100644
index 0000000..6ea4c77
--- /dev/null
+++ b/build/_routes.json
@@ -0,0 +1,4 @@
+{
+ "version": 1,
+ "include": ["/api/*"]
+}
diff --git a/build/build.mjs b/build/build.mjs
new file mode 100644
index 0000000..0d3f9d6
--- /dev/null
+++ b/build/build.mjs
@@ -0,0 +1,11 @@
+import { execSync as exec } from 'child_process';
+import { promises as fs } from 'fs';
+
+const build = async () => {
+ exec('pnpm astro build');
+ exec('pnpm astro build --worker');
+ await fs.copyFile('./build/_routes.json', './dist/_routes.json');
+ await fs.copyFile('./worker/_worker.js', './dist/_worker.js');
+};
+
+build();
diff --git a/cloudflare/env.d.ts b/cloudflare/env.d.ts
new file mode 100644
index 0000000..5b0a7e0
--- /dev/null
+++ b/cloudflare/env.d.ts
@@ -0,0 +1,2 @@
+///
+///
\ No newline at end of file
diff --git a/cloudflare/pages/api/newsletterSignup.ts b/cloudflare/pages/api/newsletterSignup.ts
new file mode 100644
index 0000000..09a43fd
--- /dev/null
+++ b/cloudflare/pages/api/newsletterSignup.ts
@@ -0,0 +1,8 @@
+import type { APIRoute } from 'astro';
+
+export const prerender = false
+
+export const get: APIRoute = async ({ params, request }) => {
+ console.log('blah', params, request);
+ return Response.redirect('https://www.google.com');
+};
diff --git a/package.json b/package.json
index 92f971c..4a9e1a4 100644
--- a/package.json
+++ b/package.json
@@ -5,7 +5,7 @@
"scripts": {
"dev": "astro dev",
"start": "astro dev",
- "build": "astro build",
+ "build": "node build/build.mjs",
"preview": "astro preview",
"astro": "astro"
},