Pages Functions in Astro don't work

Hi, I'm trying to make a Pages Function, but I'm starting to lose hope. It's basically my first time playing with it... I'm using Astro as the framework of my choice. so I made the
functions
functions
folder in the root of the project. In there I made a simple script:
export const onRequest = async (context) => {
return new Response("TEST");
};
export const onRequest = async (context) => {
return new Response("TEST");
};
After that I ran
npm run build
npm run build
and
npx wrangler pages dev ./dist
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 if that helps:
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()],
});
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()],
});
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!
4 Replies
olafg
olafg2mo ago
Can you share your Wrangler config as well?
Martokan
MartokanOP2mo ago
name = "test-project"
pages_build_output_dir = "dist"
compatibility_date = "2025-10-20"
name = "test-project"
pages_build_output_dir = "dist"
compatibility_date = "2025-10-20"
But when I tried to go thru the documentation I didn't find anything wrangler config specific to Pages Functions. Correct me if I'm wrong.
olafg
olafg2mo ago
Does the project have a _routes.json file?
Martokan
MartokanOP2mo ago
it does:
{
"version": 1,
"include": [
"/*"
],
"exclude": [
"/",
"/_astro/*",
"/favicon.svg",
"/admin/config.yml",
"/admin/index.html",
"/about",
"/booking",
"/floral-arrangements",
"/portfolio",
"/pricing"
]
}
{
"version": 1,
"include": [
"/*"
],
"exclude": [
"/",
"/_astro/*",
"/favicon.svg",
"/admin/config.yml",
"/admin/index.html",
"/about",
"/booking",
"/floral-arrangements",
"/portfolio",
"/pricing"
]
}

Did you find this page helpful?