Lotrez
Lotrez
CDCloudflare Developers
Created by Lotrez on 3/13/2024 in #pages-help
Service binding fetcher misunderstanding
I am struggling to call a worker from my pages, everything is setup but I don't understand what I need to pass to the fetcher. My code looks like this currently
const newVisitReq = await env.LOGDB_API.fetch("http://localhost:8787", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
timestamp: "2024-03-10T11:12:54.178Z",
linkId: 123,
longitude: 12.34,
listId: 1,
latitude: 56.78,
url: "https://example.com",
pathname: "/path/to/resource",
region: "Some Region",
country: "Some Country",
referer: "https://referrer.com",
timezone: "UTC",
city: "Some City",
userAgent: "Mozilla/5.0",
xForwardedFor: "192.0.2.1",
continent: "Some Continent",
postalCode: "12345",
colocation: "Some Colocation",
outcome: "Success",
host: "example.com",
}),
});
const newVisitReq = await env.LOGDB_API.fetch("http://localhost:8787", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
timestamp: "2024-03-10T11:12:54.178Z",
linkId: 123,
longitude: 12.34,
listId: 1,
latitude: 56.78,
url: "https://example.com",
pathname: "/path/to/resource",
region: "Some Region",
country: "Some Country",
referer: "https://referrer.com",
timezone: "UTC",
city: "Some City",
userAgent: "Mozilla/5.0",
xForwardedFor: "192.0.2.1",
continent: "Some Continent",
postalCode: "12345",
colocation: "Some Colocation",
outcome: "Success",
host: "example.com",
}),
});
But I fail to understand what URL I need to give the fetcher to call my worker instead of my local url and every example I found only cloned the request received by pages and passed it on. Which is not what I am trying to do. The worker I am trying to access takes the form of a REST API so I can't just pass my request.
5 replies