-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] env is not accessible writing inline #231
Comments
Do you expect env to be the cloudflare bindings (the If so:
However it would be better to add your variable to a NextJs Hope this helps. edit: fixed |
@vicb , thanks for your reply! I still think adding to I believe in your last sentence, you meant |
You are right, sorry for the confusion, I'll update my original message
It would help if you can create a minimal repro in a GH repository and attach it here. |
@vicb |
If that's the case, one way you could solve this is by changing export const api = createApiClient({ endpoint: process.env.API_URL! }); for export function getApi() {
return createApiClient({ endpoint: process.env.API_URL! });
} That way |
This is also problematic since it prevents using specific route-wrappers. import { verifySignatureAppRouter } from "@upstash/qstash/nextjs"
// 👇 Verify that this messages comes from QStash
export const POST = verifySignatureAppRouter(async (req: Request) => {
const body = await req.json()
const { imageId } = body as { imageId: string }
// Image processing logic, i.e. using sharp
return new Response(`Image with id "${imageId}" processed successfully.`)
}) does not work, due to the required env vars not being retrieved at runtime. |
@JonasDoesThings Something along those lines should work: export const POST = async (req: Request, params?: unknown) => {
// process.env is populated at that point
const handler = lazilyCreateHandler();
return await handler(req, params);
});
function lazilyCreateHandler() {
return verifySignatureAppRouter(async (req: Request) => {
const body = await req.json()
const { imageId } = body as { imageId: string }
// Image processing logic, i.e. using sharp
return new Response(`Image with id "${imageId}" processed successfully.`)
});
} |
Describe the bug
export const api = createApiClient({ endpoint: process.env.API_URL! });
not able to get process.env.API_URL
export const createApi = () => createApiClient({ endpoint: process.env.API_URL! });
able to get
Steps to reproduce
simple as write
Expected behavior
get env both
@opennextjs/cloudflare version
0.3.4
Wrangler version
3.100.0
next info output
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:30 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6000 Available memory (MB): 65536 Available CPU cores: 10 Binaries: Node: 20.10.0 npm: 10.9.2 Yarn: 1.22.19 pnpm: N/A Relevant Packages: next: 15.1.4 // Latest available version is detected (15.1.4). eslint-config-next: 15.1.4 react: 19.0.0 react-dom: 19.0.0 typescript: 5.7.2 Next.js Config: output: N/A
Additional context
No response
The text was updated successfully, but these errors were encountered: