Is it possible to deploy an arbitrary Worker using Workers for Platforms?

The title may sound unclear, so that I will give more context. Recently, I've made an application that generates a React App, compiles it using Cloudflare Containers, and deploys it to a dispatch using Workers for Platforms(WfP). John Spurlock helped me with that But now I'm unsure what WfP can and cannot do. But as you can see in both screenshots, it looks like I must use dispatcher bind to call the script I deployed. I was able to render the React app as expected, but I needed to do it inside my own worker by creating a new route nd returning my script:
app.all("/theme/live/:id/*", async (c) => {
const id = c.req.param("id");

try {
const deployedWorker = c.env.DISPATCHER.get(storeId);

[...]

const forwardedRequest = ...

const response = await deployedWorker.fetch(forwardedRequest);

return response;
} catch (deployError) {
[...]
}
});
app.all("/theme/live/:id/*", async (c) => {
const id = c.req.param("id");

try {
const deployedWorker = c.env.DISPATCHER.get(storeId);

[...]

const forwardedRequest = ...

const response = await deployedWorker.fetch(forwardedRequest);

return response;
} catch (deployError) {
[...]
}
});
But taking a look at Cloudflare for SaaS, seems like I'm missing something because If I can set custom domain for my users it implies that I can deploy stuff for my users, and in my case I would like to deploy a whole React App bundle (a single HTML and JS file) So to recapitulate, I want to deploy my bundle as a different service, because it will be my customer App, so I would like to deploy it without depending of my own Worker or something like that like by calling a dispatch bind. It should be a different App, with its own domain (or a subdomain of my domain for free plans, etc) I'm pretty sure it is possible to do with Cloudflare, I just don't know how the WfP product works, and by reading the docs, I also didn't understand it
No description
No description
2 Replies
Walshy
Walshy5mo ago
Hey! Yes, Workers for Platforms sounds perfect for what you want. You can upload sites as different user Workers which you then dispatch to. Your dispatcher will run on all customer domains and route based on how you wish (maybe hostname, some customer id, whatever fits best for you). For running on the customers domain, you'll want to add the customer domains to SSL for SaaS and get them validated. Then just make sure you have a route that can serve them, we recommend */* which will match all hostnames and all paths. This will then run all customer domains through that route. For more information, you can see this doc: https://developers.cloudflare.com/cloudflare-for-platforms/workers-for-platforms/get-started/hostname-routing/ Let me know if you have any other questions
vitor
vitorOP5mo ago
it worked thank you @Walshy | DevPlat EE :bibicat:

Did you find this page helpful?