#cloudflare wont work

1 messages · Page 1 of 1 (latest)

tiny forum
#

The redirects work in dev when I pnpm run dev but when I deploy to cloudflare they don't.

I'm using output: 'hybrid' and on certain routes/pages I have

[id].ts

---
export const prerender = false;

const { id } = Astro.params;

return Astro.redirect(`/item/${id}`);
---

And this works when I pnpm run dev but not when I deploy to cloudflare. I previously tried to define dynamic redirects like this in my astro config but it wasn't working with cloudflare so I switched to doing it manually

blissful plinthBOT
#

Hi @tiny forum. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

It seems like you're having trouble with redirects on Cloudflare using Astro. Here are a few things you could check:

  1. Redirects File: Ensure you have a _redirects file in your Astro project’s public/ folder. This file will be copied to your build output directory and used to handle redirects on Cloudflare Pages. Source (https://docs.astro.build/en/guides/integrations-guide/cloudflare/#redirects)

  2. Adapter: Make sure you're using the @astrojs/cloudflare adapter. This adapter allows Astro to deploy your hybrid or server-rendered site to Cloudflare. If you're using Astro as a static site builder, you don't need an adapter. Source (https://docs.astro.build/en/guides/integrations-guide/cloudflare/#_top)

  3. Astro Configuration: Check your astro.config.mjs file. If you're using the @astrojs/cloudflare adapter, your configuration should look something like this:

import { defineConfig } from 'astro/config';
import cloudflare from '@astrojs/cloudflare';

export default defineConfig({
  output: 'server',
  adapter: cloudflare(),
});

Source (https://docs.astro.build/en/guides/integrations-guide/cloudflare/#installation)

  1. Node.js Compatibility: Cloudflare supports a subset of the Node.js runtime APIs. If you're using these APIs, your page or endpoint must be server-side rendered (not pre-rendered) and must use the import {} from 'node:*' import syntax. Source (https://docs.astro.build/en/guides/integrations-guide/cloudflare/#nodejs-compatibility)

If you've checked all these and you're still having issues, it might be a good idea to reach out to the Astro community or Cloudflare support for more specific help.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: