I found this thread (below) and it’s the exact issue I’m having… but I don’t understand the solution in my context. I was hoping for some clarity.
Here’s the solution I found:
Here’s how I’m trying to use one of my Service Bindings.
I have a login function that checks a bunch of stuff… but if the user is in my user database, I immediately go to my app database to get their details.
I have a User Worker
that handles all backend logic for anything related to the user and their user account.
So I get the userId
and try to send the request via Service Binding like this:
getUserRequest(userId: string) {
const url = `${BASE_WORKER_PATH}/get-user`;
const auth = this.createAuthHeader(userId);
return new Request(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Basic ${auth}`,
},
});
}
This is just a little utility function to create the Request
.
I them take the returned request and go:
const getUserRes = await env.FWW_LIVE_USERS.fetch(getUserRequest);
BUT…
I know you can use paths according to the thread above. But without a path how would the request know to go to the correct handler function in my User Worker
.
I feel like I’m missing something obvious but I’m stuck right now.
How can you create a custom Request and have it get to the Worker and the correct handler?
I’ve also tried setting up a RPC connection with via a new Service Binding and an entry point. But this does not work either because the sayHello
function is not defined.
It is defined but I’m assuming this is the case because I need to setup the correct types.
const getUserRes = await env.FWW_LIVE_USERS_ADMIN.sayHello("Dan");