Repository navigation
[GIT-11] Deploy app on Cloudflare Workers #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ This guide walks you through setting up GitMarkdown from scratch, including all | |
| - [11. Apply Security Rules](#11-apply-security-rules) | ||
| - [12. Create Firestore Indexes](#12-create-firestore-indexes) | ||
| - [13. Run Locally](#13-run-locally) | ||
| - [14. Deploy to Netlify](#14-deploy-to-netlify) | ||
| - [14. Deploy to Cloudflare Workers](#14-deploy-to-cloudflare-workers) | ||
| - [Troubleshooting](#troubleshooting) | ||
|
|
||
| --- | ||
|
|
@@ -113,7 +113,7 @@ NEXT_PUBLIC_GITHUB_APP_SLUG=your_app_slug_here | |
| While in Firebase Authentication: | ||
| 1. Go to the **Settings** tab > **Authorized domains** | ||
| 2. Make sure `localhost` is listed (it should be by default) | ||
| 3. Later, add your production domain (e.g. `gitmarkdown-app.netlify.app`) | ||
| 3. Later, add your production domain (for example, `<worker>.workers.dev`) | ||
|
|
||
| --- | ||
|
|
||
|
|
@@ -407,49 +407,24 @@ Open [http://localhost:3000](http://localhost:3000). You should see the landing | |
|
|
||
| --- | ||
|
|
||
| ## 14. Deploy to Netlify | ||
| ## 14. Deploy to Cloudflare Workers | ||
|
|
||
| ### Option A: Netlify UI (recommended) | ||
|
|
||
| 1. Push your code to GitHub (make sure `.env.local` is in `.gitignore`) | ||
| 2. Go to [Netlify](https://app.netlify.com/) and click **"Add new site" > "Import an existing project"** | ||
| 3. Connect your GitHub repo | ||
| 4. Configure build settings: | ||
| - **Build command**: `npm run build` | ||
| - **Publish directory**: `.next` | ||
| 5. Go to **Site settings > Environment variables** and add all variables from your `.env.local` | ||
| 6. Click **Deploy site** | ||
|
|
||
| ### Option B: Netlify CLI | ||
| Add `FIREBASE_ADMIN_PROJECT_ID`, `FIREBASE_ADMIN_CLIENT_EMAIL`, `FIREBASE_ADMIN_PRIVATE_KEY`, and `GITHUB_TOKEN_ENCRYPTION_KEY` as Worker secrets. | ||
| Use the Cloudflare dashboard or `npx wrangler secret put --config wrangler.jsonc <NAME>`. Load `NEXT_PUBLIC_*` values during builds. | ||
|
Comment on lines
+412
to
+413
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- repository knowledge files ---'
find /tmp/coderabbit-repo-knowledge/pooriaarab-gitmarkdown-3c842ab8 -maxdepth 2 -type f -print
printf '%s\n' '--- setup excerpt ---'
sed -n '380,430p' docs/SETUP.md
printf '%s\n' '--- AI variable references ---'
rg -n -C 3 'ANTHROPIC_API_KEY|OPENAI_API_KEY|FIREBASE_ADMIN_PROJECT_ID|GITHUB_TOKEN_ENCRYPTION_KEY|wrangler secret|Worker secrets' --glob '!node_modules' --glob '!dist' .Repository: pooriaarab/gitmarkdown Length of output: 12407 🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- scoped repository guidance ---'
for f in /tmp/coderabbit-repo-knowledge/pooriaarab-gitmarkdown-3c842ab8/architecture/repo-guidelines.md \
/tmp/coderabbit-repo-knowledge/pooriaarab-gitmarkdown-3c842ab8/architecture/infrastructure.md \
/tmp/coderabbit-repo-knowledge/pooriaarab-gitmarkdown-3c842ab8/architecture/entrypoints.md; do
echo "--- $f"
cat "$f"
done
printf '%s\n' '--- AI provider implementation ---'
cat -n src/lib/ai/providers.ts
printf '%s\n' '--- chat route and one fallback route ---'
cat -n src/app/api/ai/chat/route.ts
cat -n src/app/api/ai/title/route.ts
printf '%s\n' '--- Worker configuration ---'
cat -n wrangler.jsonc
printf '%s\n' '--- deployment environment documentation ---'
sed -n '65,110p' README.md
sed -n '190,260p' docs/SETUP.mdRepository: pooriaarab/gitmarkdown Length of output: 24791 🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- non-public environment reads ---'
rg -n -C 2 'process\.env\.(?!NEXT_PUBLIC_)|process\.env\[[' --pcre2 \
src .env.example README.md docs/SETUP.md
printf '%s\n' '--- GitHub and optional provider consumers ---'
rg -n -C 4 'GITHUB_CLIENT_ID|GITHUB_CLIENT_SECRET|WAVESPEED_API_KEY' src
printf '%s\n' '--- environment template ---'
cat -n .env.exampleRepository: pooriaarab/gitmarkdown Length of output: 288 🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- environment reads ---'
rg -n -C 2 'process\.env\.' src
printf '%s\n' '--- documented non-public variables ---'
rg -n -C 1 'GITHUB_CLIENT_ID|GITHUB_CLIENT_SECRET|WAVESPEED_API_KEY|ANTHROPIC_API_KEY|OPENAI_API_KEY|FIREBASE_ADMIN_|GITHUB_TOKEN_ENCRYPTION_KEY' .env.example README.md docs/SETUP.mdRepository: pooriaarab/gitmarkdown Length of output: 13269 Add server-side AI keys to Worker secrets. When users do not provide BYOK, 🤖 Prompt for AI Agents |
||
|
|
||
| ```bash | ||
| npm install -g netlify-cli | ||
| netlify login | ||
| netlify init # Link to your repo | ||
| netlify deploy --prod | ||
| npm run build:vinext | ||
| npx wrangler deploy --dry-run | ||
| npm run deploy:vinext | ||
| ``` | ||
|
|
||
| ### Post-Deploy Checklist | ||
|
|
||
| After deploying, update these settings: | ||
|
|
||
| 1. **`.env` on Netlify**: Set `NEXT_PUBLIC_APP_URL` to your production URL (e.g. `https://gitmarkdown-app.netlify.app`) | ||
| 2. **GitHub App**: Update the **Homepage URL** to your production URL | ||
| 3. **Firebase Console > Authentication > Settings > Authorized domains**: Add your Netlify domain (e.g. `gitmarkdown-app.netlify.app`) | ||
| 4. **`FIREBASE_ADMIN_PRIVATE_KEY` on Netlify**: Make sure the private key is pasted with actual newlines. Netlify's UI handles this correctly if you paste the raw key including `\n` characters. | ||
|
|
||
| ### netlify.toml | ||
|
|
||
| Make sure this file exists in your project root: | ||
|
|
||
| ```toml | ||
| [build] | ||
| command = "npm run build" | ||
| publish = ".next" | ||
|
|
||
| [[plugins]] | ||
| package = "@netlify/plugin-nextjs" | ||
| ``` | ||
| 1. Set `NEXT_PUBLIC_APP_URL` and the GitHub App homepage to the `workers.dev` URL. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
printf '%s\n' '--- repository conventions ---'
find /tmp/coderabbit-repo-knowledge/pooriaarab-gitmarkdown-3c842ab8 -maxdepth 2 -type f -name '*.md' -print
printf '%s\n' '--- setup instructions ---'
sed -n '395,435p' docs/SETUP.md
printf '%s\n' '--- relevant references ---'
rg -n -C 3 'NEXT_PUBLIC_APP_URL|npm run build:vinext|workers\.dev|GitHub App homepage' docs/SETUP.mdRepository: pooriaarab/gitmarkdown Length of output: 3316 🏁 Script executed: #!/bin/bash
printf '%s\n' '--- applicable repository guidance ---'
cat /tmp/coderabbit-repo-knowledge/pooriaarab-gitmarkdown-3c842ab8/architecture/repo-guidelines.md
printf '%s\n' '--- deployment architecture ---'
cat /tmp/coderabbit-repo-knowledge/pooriaarab-gitmarkdown-3c842ab8/architecture/infrastructure.md
printf '%s\n' '--- app URL consumers ---'
rg -n -C 3 'NEXT_PUBLIC_APP_URL|process\.env|import\.meta\.env' --glob '!docs/SETUP.md' .Repository: pooriaarab/gitmarkdown Length of output: 13986 🏁 Script executed: #!/bin/bash
printf '%s\n' '--- exact variable usage and build configuration ---'
rg -n -C 4 'NEXT_PUBLIC_APP_URL|APP_URL|build:vinext|deploy:vinext' package.json vinext.config.* wrangler.jsonc src README.md docs/SETUP.md 2>/dev/null || true
printf '%s\n' '--- relevant environment setup ---'
sed -n '225,260p' docs/SETUP.md
sed -n '235,255p' README.mdRepository: pooriaarab/gitmarkdown Length of output: 5530 Set The deployment commands build before they deploy, but the checklist sets this build-time value afterward. Set it before 🤖 Prompt for AI Agents |
||
| 2. Complete a Firebase sign-in, then load one repository to verify Firestore access. | ||
| 3. Attach a custom domain only after its Cloudflare zone exists. | ||
|
|
||
| --- | ||
|
|
||
|
|
@@ -482,7 +457,7 @@ Same as above — Firestore rules or missing composite index. Check the browser | |
| ### `FIREBASE_ADMIN_PRIVATE_KEY` errors in production | ||
|
|
||
| - The private key contains newlines. In `.env.local`, wrap it in double quotes. | ||
| - On Netlify, paste the raw key value (the UI handles multiline values correctly). | ||
| - Preserve the key's newlines in the Cloudflare secret value. | ||
| - If you see `error:0909006C:PEM routines`, the key's `\n` characters are being treated as literal text. Make sure they're actual newline characters. | ||
|
|
||
| ### AI features not working | ||
|
|
||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: pooriaarab/gitmarkdown
Length of output: 3619
🏁 Script executed:
Repository: pooriaarab/gitmarkdown
Length of output: 6439
🏁 Script executed:
Repository: pooriaarab/gitmarkdown
Length of output: 799
🌐 Web query:
Vinext Cloudflare generated dist/server/wrangler.json wrangler deploy --config documentation💡 Result:
The command
wrangler deploy --config dist/server/wrangler.jsonis a standard way to deploy a Cloudflare Worker using a specific configuration file [1]. In the context ofvinext(a framework for running Next.js on Cloudflare Workers), this command is frequently used in CI/CD pipelines [1] or internal deployment logic to point Wrangler to the project configuration generated during the build process [2][3]. Key details regarding this workflow: 1. Context:vinextautomatically generates awrangler.jsonorwrangler.jsoncfile (often inside adist/directory) as part of its build process to define how the application should run on Cloudflare Workers [3][4]. 2. Deployment Command: Thewrangler deploycommand instructs the Cloudflare Workers CLI to upload your project [5]. By passing the--configflag, you explicitly tell Wrangler which configuration file to use, overriding the default expectation that the file resides in the root directory [1][6]. 3. Automation: If you are encountering issues where a deployment script expectsdist/server/wrangler.jsonbut it does not exist, it may indicate that the build step responsible for generating that configuration failed or was skipped [7]. Ensure that you have run the necessary build command (e.g.,vinext deployor the build script configured in yourpackage.json) before attempting to execute the deployment command [3][8]. 4. Best Practices: Cloudflare recommends usingwrangler.jsoncfor new projects as it supports advanced configurations [6]. While older workflows may usewrangler.json, the structure and the--configflag remain functional in current versions of Wrangler [6]. If you are automating this, you can runvinext deploydirectly, which handles the orchestration of building the project and executing the deployment using the generated configuration automatically, rather than manually invokingwrangler[3][9].Citations:
Run the dry run with the generated Vinext configuration.
After
npm run build:vinext, runnpx wrangler deploy --dry-run --config dist/server/wrangler.json. The bare command uses the rootwrangler.jsonc, so it can validate different Worker and asset settings thandeploy:vinext.🤖 Prompt for AI Agents