Cloudflare DevelopersCD
Cloudflare Developers4mo ago
5 replies
Martokan

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
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 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()],
});


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!
Was this page helpful?