From Homelab to Workers: What an Adapter Swap Doesn’t Move
Ślubne Chwile ran as an Astro Node app on my homelab, reached through a Cloudflare Tunnel. The goal was to serve it from a Cloudflare Worker on the free plan, with no upfront plan upgrade, while keeping the homelab as a rollback.
The plan on day one was one line: switch the Astro adapter to Cloudflare and deploy. This chapter is why that wasn’t the plan for long.
The Build Passed. The App Didn’t.
The adapter swap built fine. A local Worker health request then failed:
firebase-admin/firestore pulls in protobufjs, which generates code at
runtime, and the Worker runtime doesn’t allow that.
A successful bundle is not evidence that the server code runs. A bundler will happily package Node dependencies that only fail when a request arrives. Test the runtime boundary first, before you write a deployment plan.
A Separate Implementation, Not an In-Place Rewrite
The Node app already carried the wedding schema, Firebase Auth, private media, payment rules and the homelab route. Rewriting it in place would have made every half-finished step a production deployment.
So the Worker became a separate folder, next to the untouched Node app. It reused the product contract and the existing data, but its server side was written for the runtime:
| Need | Node version | Worker version |
|---|---|---|
| Database access | firebase-admin SDK | Firestore REST API |
| Service-account auth | SDK handles it | Web Crypto signs the assertion, exchanged for a short-lived Google token |
| User ID tokens | SDK verifies | Signature and claims checked against Google’s rotating keys, then the live account state |
| Media | Server receives the file | R2 binding plus direct browser upload (next chapter) |
| Public pages | Astro server | Prerendered from the Astro app as Worker static assets |
The last row matters for a small business: the marketing and legal pages stayed in the original Astro source. There is still one copy of the copy.
One detail on tokens: a valid signature isn’t enough. The Worker also looks up whether the account still exists and is enabled. A token is proof of who someone was at sign-in, not of whether they should still get in.
Preview With the Writes Switched Off
The first deployed Worker had its own workers.dev hostname and a write
gate set to off. That address was used to check, in order:
- Health and protected readiness.
- Real Firebase reads.
- Static pages.
- Synthetic write flows, on disposable records deleted after each drill.
Meanwhile the real domain kept going through the Tunnel to the homelab.
Two Wrangler config files, preview and production, differ only in their gates and the route. A small parity-check script asserts that those are the only differences, so “it worked on preview” means something.
Tests That Lied by Omission
Two failures got past green test suites.
The auth popup. The browser checks used disposable Firebase users, and
they passed: session persisted, wedding loaded, dashboard reached. Then a
real Google sign-in failed with “missing initial state”. The project’s
default Firebase Hosting site existed but had never had a release, so its
reserved /__/firebase/init.json endpoint returned 404, and the OAuth helper
had nothing to read. A minimal Hosting release fixed it, and Google and
email-link sign-in then both completed on the production domain.
A popup reaching accounts.google.com is only an intermediate milestone.
The guest page. API tests passed, but the deployed guest page couldn’t finish an upload: the browser script had been packaged wrongly. Declaring the guest code as an explicit Wrangler static asset fixed it; a real Chrome upload passed on retest. Server tests don’t prove the browser received working JavaScript.
The pattern in both: prove the schema in an emulator, then prove the flow in a real browser, with a real account.
Cutover Was a Route, Not a Migration Day
The domain already pointed at a proxied Tunnel to the homelab. The Tunnel’s DNS record stayed exactly as it was. A Worker route was attached in front of it.
That makes rollback one command: redeploy the preview config, which has no custom route, and traffic falls through to the homelab again.
Before the switch:
- Secrets copied to ignored local files and installed in the Worker and in GitHub.
- Hosted backup and restore evidence verified (chapter 15).
- The protected health token aligned with the existing off-host monitor.
- Both configs built and dry-run.
- Preview passed: guest upload, owner gallery and export, deletion, public pages, support, and a Stripe test payment.
After the switch: public and protected health returned 200, then upload, private reads, sign-in, QR downloads, gallery and ZIP export all passed on the production hostname. The homelab monitor kept reporting success.
What’s Still Open, Written Down
The migration notes don’t end with “done”. They end with a list:
- Large-gallery and production-scale CPU behaviour not measured.
- The route rollback not yet exercised in a planned drill.
- Concurrent and mobile network-interruption upload cases still open.
- Live payments a separate decision: checkout is still off.
Takeaways
- Run one real request in the target runtime before planning anything.
- Build the new version next to the old one. Keep the old one deployable.
- Preview with writes off, and make the preview/production difference checkable by a script.
- Real browser, real account before you call auth done.
- Make cutover a reversible route change, and keep the old origin’s DNS.