Local development with service bindings gives error when calling service

I am developing a worker locally using a service binding to another worker. When I call the fetch function of the bound worker (running in another terminal with wrangler dev) I get an error from worker middleware saying 'Invalid URL String` The url I am passing is just cloned from the original request... has anyone seen this before?
3 Replies
CB
CBOP16mo ago
Here is what my code looks like:
var postBody = {
"action": "LeadsList",
"token": credentials.token,
}


var clonedRequest = request.clone();

var zohorequest = new Request({
url: clonedRequest.url,
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(postBody),
})

var zohoresponse = await env.zohocrm.fetch(zohorequest)
var postBody = {
"action": "LeadsList",
"token": credentials.token,
}


var clonedRequest = request.clone();

var zohorequest = new Request({
url: clonedRequest.url,
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(postBody),
})

var zohoresponse = await env.zohocrm.fetch(zohorequest)
kian
kian16mo ago
That isn't how new Request should be constructed, you're passing an object (which inherently isn't a valid URL)
CB
CBOP16mo ago
oh, I am sorry. I didn't realize i was doing that wrong. what URL should I use when trying to hit another service with a service binding I see what you mean. It is new Request (url, options) I will fix that. Sorry for submitting a javascript issue.
Want results from more Discord servers?
Add your server