Multi-Worker Configuration with EKS Integration for Single Domain
What steps have you taken to resolve the issue?
Subject: Multi-Worker Configuration with EKS Integration for Single Domain
Description:
I need to implement a routing solution for my domain (domain.com) that involves multiple Cloudflare Workers and an Amazon EKS cluster. Here are the specific requirements:
Multiple Workers Configuration:
Need to deploy and manage multiple Cloudflare Workers on a single domain
Each Worker should handle different routes (URL paths)
Workers should be configured to respond to specific HTTP methods
Example: domain.com/* → Worker A, domain.com/feature/* → Worker B
EKS Integration:
Need to route specific paths to an Amazon EKS cluster
Example: domain.com/api/* should route to EKS Load Balancer
Require proper configuration to maintain security and performance
What comes to my mind is to call a Worker with another Worker:
Otherwise, if you’re doing it within the same domain, then the domain.com/feature/* would take precedence over domain.com/*.
WorkerA Route: domain.com/*
WorkerB Route: domain.com/feature/*
The worker for /feature/* will take precedence when the URL matches both patterns from my experience.
So for your Worker route, make sure the first one is for the specific route (domain.com/feature/*) for WorkerB, followed by the 2nd more general route (domain.com/*) for WorkerA.
If domain.com/* is defined before domain.com/feature/*, then WorkerA will handle all requests, including those to /feature/*—and WorkerB won’t even get a chance to handle them.
You could add a behaviour, or request URL check in your 1st Worker, e.g. if URL path contains feature then proceed further and I guess the 2nd Worker then would fire.
May I ask if you’re using a Free or paid plan type for your Website?
Snippets might help as well.
So for worker route handling I think we can use worker routing that is good and it is working. But lets say I want to call another url or domain. Lets say what if I hit /api and it should go for my api which is not running on worker but some other place. So is that possible?
Since you’d have a Worker which would be bound to the /* route and fire on every request as domain.com/*, in this Worker which is set to route domain.com/* (matches even domain.com/api*) you can add a logic part to check if the URL path contains /api then proceed with the request, otherwise do something else (what the Worker should do).
Example:
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const url = new URL(request.url)
// Check if the URL path starts with '/api'
if (url.pathname.startsWith('/api')) {
// Proceed with the request if it's domain.com/api or something after it domain.com/api/abcdef?param=value
return fetch(request)
} else {
// Do something else for other requests which you want to do as of domain.com/*
return ... or redirect ...
}
}