andifined.dev
andifined.dev
CDCloudflare Developers
Created by andifined.dev on 3/9/2024 in #workers-help
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.
3 replies
CDCloudflare Developers
Created by andifined.dev on 1/27/2023 in #pages-help
best practices for .pages.dev domain
Hey, I‘m looking for a way to handle the standard .pages.dev domains. I would like to keep headers and cache settings out of my application, cause I thinks it‘s not business logic related as much. So I added page and transform rules for the official domain and it works great, but I‘m don‘t know how to handle the preview generated subdomains for the project. I don’t want that it‘s possible to access the page by the .pages.dev domain, so I added a bulk redirect for it. Works fine as well, but I want to keep the preview urls accessible with custom no-follow tags. Is it possible to achieve that?
12 replies