Reverse Proxy for custom domains with subdirectories on my apidocs

I am facing a problem while trying to implement a Reverse Proxy in my API Gateway for it to display my apidocs.

My usecase is a little bit strange, but it is that way because I want to keep my stack as free as possible. I’m using a Cloudflare Worker (JavaScript) as an API Gateway, everything is working fine there under a api.<domain>.com subdomain (you can access our different services using subdirectories like /accounts. The thing is that for every service, I would like to set up another subdirectory for its apidocs (api.<domain>.com/<service/docs.

When publishing a documentation site on Apidog, I selected the Reverse Proxy option along with the ‘Use subdirectory’ checkbox. My custom domain looks like this: https:// api.<domain>.com / accounts/docs.
On my API Gateway code, I implemented a Reverse Proxy that allows me to access to the apidocs on that custom domain, but some 404 errors get thrown through the console, and my endpoints doesn’t show any details, it just says “Page Not Found” and a button to reload.

I know this is not exactly related to Apidog, but to how to develop a correct Reverse Proxy on JavaScript for this to work properly.
Here, I provide my Reverse Proxy approach:

if(request.url.endsWith(`${env.ACCOUNTS_PATH}/docs/`)) {
    return reverseProxyForService(request, env.ACCOUNTS_PATH, env.ACCOUNTS_APIDOCS_ID);
}

// In a different file.
module.exports = async function reverseProxyForService(request, servicePath, apiDocsID) {
    const apidogUrl = new URL(request.url)
    apidogUrl.hostname = `${apiDocsID}.apidog.io`
    apidogUrl.pathname = apidogUrl.pathname.replace(`${servicePath}/docs/`, '')

    const apidogRequest = new Request(apidogUrl, {
        method: request.method,
        headers: request.headers,
        body: request.body
    })

    apidogRequest.headers.set('X-Apidog-Docs-Site-ID', apiDocsID)
    apidogRequest.headers.set('Host', `api.<domain>.com/${servicePath}/docs/`)

    return fetch(apidogRequest)
}

Sorry if my explanation is a little bit odd, I’m unsure of how to phrase my issue and how my stack is developed. But, of course, I would give more details if needed for you to help me.
Thanks in advance!

Hi, could you please provide the Custom Domain of the apidocs?

Still with the same problem, tried different workarounds and none of them solved my situation. Does somebody know how this works or could provide me some resources?

ToxYc I think you set the wrong host in your worker code. the host should be set your custom domain name ‘api.<domain>.name’. Here is the documentation link Custom domain - Apidog Docs

@here
Ok, I changed it, but still the website is now trying to access this kind of endpoints: https://api.gycoding.com/raiz5jee8eiph0eeFooV/api/v1/published-projects/domains/api.gycoding.com, and, of course, not finding anything on them (404). I don’t really know what to do there with those accesses.