Hi,
I'm trying to use a Pages Function on Cloudflare, but I'm starting to lose hope. It's basically my first time playing with it...
so I made the functions folder in the root of the project. In there I made a simple script:
export const onRequest = async (context) => {
return new Response("TEST");
};
After that I ran npm run build and npx wrangler pages dev ./dist.
Then when I try to hit: http://127.0.0.1:8788/test
It only returns my index page. So there is some problem.
This is my Astro config:
import { defineConfig } from 'astro/config';
import tailwind from '@astrojs/tailwind';
import react from '@astrojs/react';
import cloudflare from '@astrojs/cloudflare';
export default defineConfig({
output: 'static',
adapter: cloudflare(),
integrations: [tailwind(), react()],
});
Here's wrangler config:
name = "test-project"
pages_build_output_dir = "dist"
compatibility_date = "2025-10-20"
Here's _routes.json:
{
"version": 1,
"include": [
"/*"
],
"exclude": [
"/",
"/_astro/*",
"/favicon.svg",
"/admin/config.yml",
"/admin/index.html",
"/about",
"/booking",
"/floral-arrangements",
"/portfolio",
"/pricing"
]
}
I'm not sure if I'm missing any configuration or not doing something important in order for the functions to work.
I did try to run the project both locally and on CF with the same result, pages functions don't work.
I'll much appreaciate any help!