Not able to parse request body when using service bindings

Hello everyone, I would like to use service bindings and implemented a PoC according to the official documentation: https://developers.cloudflare.com/workers/configuration/bindings/about-service-bindings/ But I'm facing a problem now and don't know how to tackle it. I would like to parse the request body, after the authentication was successful and it works on my machine (haha), but after deployment the request takes forever and then timesout. My code looks like this:
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
const authResponse = await env.AUTH.fetch(request.clone());

if (authResponse.status !== 200) {
return authResponse;
}

const { url, method } = request
const { pathname } = new URL(url)

const [service] = pathname.substring(1).split('/')

switch (service) {
case 'service-1':
return await env.SERVICE1.fetch(request)
}

return new Response('Not found', { status: 404 })
}
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
const authResponse = await env.AUTH.fetch(request.clone());

if (authResponse.status !== 200) {
return authResponse;
}

const { url, method } = request
const { pathname } = new URL(url)

const [service] = pathname.substring(1).split('/')

switch (service) {
case 'service-1':
return await env.SERVICE1.fetch(request)
}

return new Response('Not found', { status: 404 })
}
Within service-1:
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
const url = new URL(request.url)
const [_, __, generateFor] = url.pathname.split('/')
const { label } = await request.json<{ label: string }>()

return new Response(label)
}
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
const url = new URL(request.url)
const [_, __, generateFor] = url.pathname.split('/')
const { label } = await request.json<{ label: string }>()

return new Response(label)
}
What am I missing here? As far as I got it debugged, I know it's the await request.json() that seems to be the problem.
Cloudflare Docs
Service bindings - Configuration · Cloudflare Workers docs
Service bindings are an API that facilitate Worker-to-Worker communication via explicit bindings defined in your configuration.
2 Replies
kian
kian9mo ago
Are you getting an error, or the request just hangs? Is this when deployed or when doing local development?
andifined.dev
andifined.devOP9mo ago
It hangs completely. Locally it works flawless, just the deployment has a problem.
Want results from more Discord servers?
Add your server