withastro / adapters

Home for Astro's core maintained adapters
64 stars 33 forks source link

Cloudflare build output changes response headers and doesn't log #221

Closed sjunepark closed 6 months ago

sjunepark commented 6 months ago

Astro Info

Astro                    v4.5.14
Node                     v20.11.0
System                   macOS (arm64)
Package Manager          pnpm
Output                   hybrid
Adapter                  @astrojs/cloudflare
Integrations             none

Describe the Bug

Hi, I'm not 100% sure these are bugs or just skill issues, but have noticed the problems below which I couldn't figure out why.

In astro dev everything seems to work fine, but the wrangler pages dev dist version and the actual cloudflare deployed versions have the problem below.

// src/pages/greet.ts
import type { APIRoute } from 'astro'

export const GET: APIRoute = () => {
    console.log("Shouldn't this be logged?")
    return new Response(
        JSON.stringify({
            greeting: 'Hello',
        }),
        {
            headers: {
                'content-type': 'application/json',
            },
        }
    )
}
  1. The endpoint returns header of 'content-type': 'application/octet-stream'
  2. The console.log doesn't log anything to the console. (I've tried changing the --log-level during wrangler pages dev but this doesn't seem to be the issue.

Here is a simple reproduced repo for this, thanks.

What's the expected result?

  1. The endpoint should returns header of 'content-type': 'application/json' as specified in the source code.
  2. The console.log should be logged

Link to Minimal Reproducible Example

https://github.com/sjunepark/astro-cf-reproduce

Participation

dallyh commented 6 months ago

Hello, you're using hybrid output mode, that means all of the routes are prerendered by default. Try adding export const prerender = false to the greet endpoint.

sjunepark commented 6 months ago

@dallyh Glad this was my issue, thank you so much!