#400s for api routes (maybe since adding the cloudflare adapter?)

1 messages ยท Page 1 of 1 (latest)

fiery carbon
#

First attempt at hosting an SSR site on cloudflare pages/workers so it might have nothing to do with the cloudflare adapter at all! but my routes locally have all started returning 400. Just wondered if it could be related to the way cloudflare adapter handles function/routing and something changed for me locally too? Previously they were working fine

src
|-pages
| |-api
| |  |-dvla.ts
| |  |-enquiry.ts
| |-index.astro
|
|-components

Routes called from components using fetch, like this in my MultiStepForm component:

const response = await fetch("/api/enquiry", {
  method: "POST",
  body: JSON.stringify({
    ...data
  }),
});

enquiry.ts

export const POST: APIRoute = async ({ request }) => {}

All had been working fine. I've linked the error from chrome inspector below. Thanks for taking a look ๐Ÿ™‚

river coyote
#

What does your code look like?

fiery carbon
river coyote
#

What is your output? Is it server or hybrid?

fiery carbon
#

oh sorry i thought I posted that. hybrid:

export default defineConfig({
  output: 'hybrid',
  adapter: cloudflare({
    imageService: 'compile'
  }),
  integrations: [react(), tailwind({
    applyBaseStyles: false
  })],
  server: { port: 1234, host: true}
});
river coyote
#

At the top of your API Route. Add export const prerender = false and try that

fiery carbon
#

I have that already unfortunately

river coyote
#

Hmm that is odd

fiery carbon
#

this had all been working fine locally

#

should i try removing the adapter?

river coyote
#

When did it start failing?

fiery carbon
#

well i think around the time i added the cloudflare adapter, but i'm not 100%.

river coyote
#

Is your repo open? Can I take a look?

fiery carbon
#

let me check ๐Ÿ™‚

river coyote
#

I think your Turnstile token is failing.

fiery carbon
river coyote
#

Im actually using it in my project and it works great. Do you wanna hop on a call and I can show you? Can also show you a different way to send emails that works great!

fiery carbon
#

yeah, thanks. any chance you can give me like 5 minutes please? need to find headphones ๐Ÿ˜„

river coyote
#

Sure thing

fiery carbon
#

right nice one, sorry about that, just moved back from canada so everything has been packed

river coyote
#

Oh nice. Just a sec and we can get on a call. Had another call come in

fiery carbon
#

yeah take your time, no rush

river coyote
#

Almost done with this call! Freaking printer issues man

fiery carbon
#

Oh god. My family gets 1 printer support voucher per year. That's my limit. I'm even thinking about making them share. ๐Ÿ˜„

fiery carbon
#

Got the routes sorted - it was hitting it, it was me returning the 404 ๐Ÿ˜„

Would still be keen to see a good turnstile implementation though - it's always something I feel like I'm hacking my way through. Both with the react-turnstile package, and when i used it without

river coyote
#

Sorry got sidetracked with tons of calls. Yes! I can defintely help you with that

fiery carbon
#

amazing, thanks. would tomorrow be ok? or whenever's convenient really. just a bit late here now ๐Ÿ™‚

river coyote
#

Yes. Tomorrow sounds great

river coyote
#

Hey man. Whenever you are free. We can hop on a call

fiery carbon
#

Hi bud, yeah I've just got some food coming ๐Ÿ™‚
Also should I get my domain set up first so we're working with the right url for turnstile? Or is it more just showing me some code you've got?

river coyote
#

Just showing the code. You can use it with localhost

fiery carbon
#

oh ok awesome, can do it now then if you like?