Our idea is to run multiple stages of an app as multiple Fly.io apps like: alpha-my-app.fly.dev
, beta-my-app.fly.dev
and stable-my-app.fly.dev
.
With routing table of project domains mapped to those stages - so we can pick and change which stage any domain currently runs on.
const router = {
"project1.my-saas.com": "stable-my-app",
"project3.my-saas.com": "stable-my-app",
"project4.my-saas.com": "beta-my-app",
"project5.my-saas.com": "alpha-my-app",
}
What we need is of course possible by changing CNAME
, but we would very much like to minimize the need to change DNS.
I imagine we can deploy a gateway/proxy/router app that would hold the routing table and then use Dynamic Request Routing with fly-reply: app=beta-my-app
header.
This works, but Dynamic Request Routing is limited to 1MB requests which at the moment sounds reasonable, but in the future this might become painful. Also not sure how optimal this flow is around traffic pricing etc.
// Using Dynamic Request Routing this works too:
Bun.serve({
async fetch(req) {
const url = new URL(req.url)
const rewriteToApp = router[url.hostname]
if (found) {
return new Response('', {
headers: {
'fly-replay': `app=${rewriteToApp}`,
},
})
}
return new Response(`Invalid hostname ${url.hostname}`)
},
})
console.log('Running', server.hostname, server.port)
Ideally we could create aliases for fly.io apps - that would allow me to configure each project CNAME to its own fly.io app alias. And then just switch which alias belongs to which app.
# my imagined commands would look like these:
flyctl alias add project1 --app=stable-my-app
flyctl alias add project2 --app=alpha-my-app
Other topic I found in docs is Flycast, but I am not very sure how that works.
Do you have any recommendations, notes or tips?
Thank you.