Calling any function route gives 404 with Docusaurus

Hello,

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: https://a1843492.pglet-website.pages.dev
Trying to call function route gives 404: Last build: https://a1843492.pglet-website.pages.dev/tools/signup
Though I can see function source: Trying to call function route gives 404: Last build: https://a1843492.pglet-website.pages.dev/functions/tools/signup.js

I also made another trivial web site (GitHub - appveyor/website-cfp: AppVeyor website on Cloudflare Pages) just to test functions and it worked: https://5d472d2b.appveyor-website.pages.dev/tools/my-ip

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.