Trying to create separate Stream accounts for webhooks to separate URLs

We have the same website hosted at 2 URLs for our different environments. For example:

https://abc.com - production website instance
https://dev.abc.com - development website instance

We are using Stream for video hosting and till now using the same Stream account for both of the environments. However, we need to setup webhooks now to be notified when a video processing has been completed and only then start showing that video in the feed.

However, the documentation over here states that we can only setup a single webhook per Cloudflare account. But we need to hit separate webhooks for the 2 environments. If a video has been uploaded from the dev environment, the webhook has to be posted to an API on the dev environment for the right video record in the database to be updated. Same goes for the production environment.

Please let us know how to proceed

Do you already have two different Cloudflare accounts to represent “dev” and “prod” environments?

If you did, then you could configure the webhook URL for your Stream Dev account to your dev server and the webhook in Stream Prod account to your prod server right? Let me know if I am misunderstanding something.

It doesn’t seem that way. It looks like they’re both in the same zone, which would make it difficult to split into two Cloudflare accounts.

Got it. I was a bit confused reading the title of the post which implies separate accounts.

My advise to the OP would be to set up a separate Cloudflare account for dev environment. We plan to make major upgrades to webhooks in coming quarters so we can support multiple URLs from a single cloudflare account. Having entirely separate cf account would be the best interim solution.

The other workaround if you really want to avoid a separate account is to write a Worker and point all webhook requests to that worker. The Worker can then determine if its a prod or dev video and reroute the request to the appropriate dev/prod endpoints on your origin.

They’d have to move their dev environment to a completely different domain. And it would have to be on a separate Cloudflare account.

We dont have separate Cloudflare accounts.

That would be a last resort as that would mean I would need separate email accounts. As this is a work account, I would then need to setup separate email accounts on this domain or an account on a different domain.

I would also have to setup a new domain on the new account that I would need to create and connect cloudflare to the same. Then I would need to move my dev environment from dev.abc.com to xyz.com

Finally, I would need to procure a new Cloudflare Stream subscription for the same.

This is absolutely a last resort. I would prefer if there were an easier solution.

It would be preferable if this could be avoided. Any other workarounds?

The easiest workaround would be to setup a Cloudflare Worker script and configure Stream to send all requests to it. The Worker script can redirect the request to your prod or staging environment.

I’ve put together a quick example here: stream-examples/webhook-redirect-worker.js at main · zaidf/stream-examples · GitHub

In my example, if the video file name contains “staging-”, the webhook will be sent to the staging URL configured at the top of the script. All other requests will goto prod.

2 Likes

Thank you for the example. However, it would require us to maintain another API on Cloudflare and get billed for it separately.

So, we ended up going with a interval based polling solution that will query the Cloudflare API for stream readiness check and mark the video processed if cloudflare responds with “ready”

1 Like

Got it. Please note that Workers provides a free tier with 100K free requests/day: https://developers.cloudflare.com/workers/platform/limits#worker-limits