Hands-on Lab: Deployment
In this final lab, you will go through the complete deployment lifecycle for your Task Manager application.
Objective
Section titled “Objective”By the end of this exercise, you will have:
- Configured your Cloudflare environment.
- Provisioned a remote D1 database.
- Deployed your application to the edge.
- Debugged a simulated production issue.
Prerequisites
Section titled “Prerequisites”- A completed Task Manager (
tm) project from previous modules. - A Cloudflare account.
Part 1: Infrastructure Setup
Section titled “Part 1: Infrastructure Setup”-
Login to Wrangler Run
bunx wrangler loginand authorize your machine. -
Create Database Create a new D1 database named
tm-prod.💡 Hint: Command
Terminal window bunx wrangler d1 create tm-prod -
Update Configuration Update your
wrangler.jsonwith the new database ID.
Part 2: Database Migration
Section titled “Part 2: Database Migration”-
Apply Migrations Apply your existing migrations to the new
tm-proddatabase.💡 Hint: Command
Terminal window bunx wrangler d1 migrations apply tm-prod --remote -
Verify Tables Run a SQL command to list tables in the remote database to confirm they exist.
Part 3: Deployment
Section titled “Part 3: Deployment”-
Set Secrets Set the
BETTER_AUTH_SECRETfor your production worker. -
Deploy Build and deploy your application.
💡 Hint: Command
Terminal window bun run buildbunx wrangler deploy -
Test Visit your deployed URL. Try to sign up.
Part 4: Troubleshooting Challenge
Section titled “Part 4: Troubleshooting Challenge”Scenario: You deployed your app, but when you try to login, nothing happens, and you see a console error in the browser about “CORS”.
Task:
- Use
wrangler tailto see if the request is reaching your backend. - Identify where the CORS configuration is in your code.
- Update the allowed origins to include your new production URL.
- Redeploy the application.
💡 Hint: CORS Config
Look in src/worker/index.ts. You need to add your https://tm.<subdomain>.workers.dev URL to the origin array in the cors() middleware.
Verification Checklist
Section titled “Verification Checklist”-
wrangler.jsonhas the correctdatabase_id. - Remote database has
usersandtaskstables. -
BETTER_AUTH_SECRETis set in Cloudflare. - Application is accessible via a public URL.
- You can successfully log in and create a task on the live site.
Congratulations! 🎓
Section titled “Congratulations! 🎓”You have completed the Full-Stack Course! You have built, tested, and deployed a modern full-stack application.