Hi there, has anyone had any luck with using a Cloudflare worker to reverse proxy the data plane url for the v3 SDK? I have created a worker with the below code (KV is the data plane url) but can't see any events come through when testing.
export default {
async fetch(request, env, ctx) {
// Check the request URL path for the SDK route
const url = new URL(request.url);
// Define the path where you want to serve the SDK
const SDK_PATH = '/sdk'; // Customize this path as needed
if (url.pathname === SDK_PATH) {
// If the request matches the SDK route, fetch the SDK
const SDK_URL = '
https://cdn.rudderlabs.com/beta/3.0.0-beta';
const response = await fetch(SDK_URL);
// Return the response received from the SDK URL
return response;
}
// If the request does not match the SDK route, handle other routes
async function fetchOriginMappings(hostname) {
return await env.KV.get(hostname);
}
async function handleRequest(request) {
const DATA_PLANE_URL = await fetchOriginMappings(url.hostname);
// Check if incoming hostname is a key in the originMappings object
if (DATA_PLANE_URL) {
url.hostname = DATA_PLANE_URL;
// Forward the request to the third-party origin
const response = await fetch(url.toString(), request);
// Check the response status and handle accordingly
if (response.status === 200) {
// If it is a successful response, return it
return response;
} else {
// Handle other response statuses as needed
return new Response("Proxy request failed", {
status: response.status,
statusText: response.statusText,
});
}
}
// Otherwise, return a 401 Unauthorized response
return new Response("Unauthorized", { status: 401 });
}
return handleRequest(request);
},
};