If you update examples/playground/api/env as follow:
import { getCloudflareContext } from "@opennextjs/cloudflare";
// the output.
export const dynamic = "force-dynamic";
console.log(getCloudflareContext());
export async function GET() {
return new Response(JSON.stringify(process.env));
}
Note: calling getCloudflareContext is not actually supported at top level but I'm working on adding support for that.
It would log an incorrect message (the route is dynamic):
ERROR: `getCloudflareContext` has been called in a static route, that is not allowed, this can be solved in different ways:
- call `getCloudflareContext({async: true})` to use the `async` mode
- avoid calling `getCloudflareContext` in the route
- make the route non static
- This is not a static route
getCloudflareContext({async: true}) seem to work
We should first fix the error message.
It would also be nice that we could make {async: false} work here if possible