Skip to content

Instantly share code, notes, and snippets.

View reggeenr's full-sized avatar

Enrico Regge reggeenr

  • IBM
View GitHub Profile
@reggeenr
reggeenr / cloudflare-edge-function-that-directs-traffic-to-an-ibm-cloud-code-engine-app.js
Created May 2, 2022 11:16
This code snipped can be used to create a Cloudflare Edge Function that directs all requests to an IBM Cloud Code Engine application
addEventListener('fetch', (event) => {
    const mutable_request = new Request(event.request);
    event.respondWith(directRequestToCodeEngineApp(mutable_request));
});
async function directRequestToCodeEngineApp(request) {
    // FQDN of the Code Engine application that should receive the traffic
    const targetHost = '<app-name>.<randomcharacters>.<region-name>.codeengine.appdomain.cloud';