Calling any function route gives 404 with Docusaurus


I’m trying to use Cloudflare Pages Functions with Docusaurus site. I’ve put test functions/tools/signup.js and made sure it’s copied to a site output. The contents of signup.js:

export async function onRequest(context) {
    // Contents of context object
    const { request } = context;
    const clientIP = request.headers.get("CF-Connecting-IP");
    return new Response("Your IP: " + clientIP);

However, visiting http://{site-temp-url}/tools/signup gives 404 page instead of running a function and displaying IP address. What’s interesting I can browse to http://{site-temp-url}/functions/tools/signup.js and see JS source - so, the file is there. It looks like /functions directory is not picked up/ignored by Cloudflare Pages.

Sources: GitHub - pglet/website at subscribe-form
Last build:
Trying to call function route gives 404: Last build:
Though I can see function source: Trying to call function route gives 404: Last build:

I also made another trivial web site (GitHub - appveyor/website-cfp: AppVeyor website on Cloudflare Pages) just to test functions and it worked:

What am I doing wrong? Must be something simple and obvious, right?

Try moving the functions folder from the static folder to the root level (up one level).

Wow, that worked! /functions directory should not be built together with the site and must be just in the root of the repo.

Thank you for the fast response!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.