Deploying the App
Now that our infrastructure is ready, we can deploy the application. This involves building the frontend, configuring secrets, and pushing the code to Cloudflare.
Environment Variables & Secrets
Section titled “Environment Variables & Secrets”In development, we used a .env file for secrets like BETTER_AUTH_SECRET. In production, we cannot simply upload this file for security reasons. Instead, we use Wrangler Secrets.
-
Set the Auth Secret
Generate a secure random string for your production auth secret (you can use
openssl rand -hex 32or a password generator).Terminal window bunx wrangler secret put BETTER_AUTH_SECRETPaste your secret value when prompted.
-
Set Other Secrets
If your application uses other secrets (e.g.,
GOOGLE_CLIENT_ID,GOOGLE_CLIENT_SECRETfor OAuth), set them in the same way:Terminal window bunx wrangler secret put GOOGLE_CLIENT_IDbunx wrangler secret put GOOGLE_CLIENT_SECRETNote: Non-secret environment variables (like public API URLs) can be added to the
[vars]section ofwrangler.json, but sensitive data must always usewrangler secret put.
Building and Deploying
Section titled “Building and Deploying”-
Build the Project
We need to compile our TypeScript backend and build our React frontend into static assets.
Terminal window bun run buildThis command typically runs
tsc(TypeScript compiler) andvite build. The frontend assets will be output todist/client. -
Dry Run (Optional)
Before the real deployment, you can check if everything looks correct.
Terminal window bun run checkThis runs a build and a dry-run deployment, showing you what would be uploaded.
-
Deploy to Production
Finally, push your application to the edge!
Terminal window bunx wrangler deployWrangler will upload your worker code and your static assets. Once finished, it will print your deployed URL:
https://tm.<your-subdomain>.workers.dev
Custom Domains (Optional)
Section titled “Custom Domains (Optional)”If you own a domain name, you can connect it to your Worker.
- Go to the Cloudflare Dashboard.
- Navigate to Workers & Pages > Select your
tmworker. - Go to Triggers > Custom Domains.
- Click Add Custom Domain and enter your domain (e.g.,
app.yourdomain.com).
Cloudflare will automatically handle the DNS records and SSL certificates for you.
Verifying the Deployment
Section titled “Verifying the Deployment”Open your deployed URL in a browser.
- You should see your React application load.
- Try signing up and logging in.
- Create a task.
If everything works, congratulations! You have a live full-stack application. 🎉