PneuTueur
PneuTueur
CDCloudflare Developers
Created by PneuTueur on 8/28/2024 in #workers-help
Why do all workers use for same IP for sending requests?
It seems that all the requests sent by workers show the same IP (2a06:98c0:3600::103), as we can see when we request, e.g., https://icanhazip.com/. This behaviour is somewhat unfortunate in cases where we use several workers for webscraping. In my case, if two workers happen to make the same request to a website I want to scrape data from, one of them is refused. Can this be changed by some operation?
8 replies
CDCloudflare Developers
Created by PneuTueur on 8/26/2024 in #workers-help
Cannot find module '__STATIC_CONTENT_MANIFEST' or its corresponding type declarations
I'm using Hono and I want to serve some static files with my Cloudflare worker. I followed the docs and added a worker-site bucket which is the place where my static files are stored, and my index.ts now looks like this:
import { Hono } from 'hono'
import { serveStatic } from 'hono/cloudflare-workers'
import manifest from '__STATIC_CONTENT_MANIFEST'

const app = new Hono()

app.get('/favicon.ico', serveStatic({ path: './static/favicon.ico', manifest }));

export default app;
import { Hono } from 'hono'
import { serveStatic } from 'hono/cloudflare-workers'
import manifest from '__STATIC_CONTENT_MANIFEST'

const app = new Hono()

app.get('/favicon.ico', serveStatic({ path: './static/favicon.ico', manifest }));

export default app;
However TypeScript says: Cannot find module '__STATIC_CONTENT_MANIFEST' or its corresponding type declarations. How to solve this issue?
3 replies
CDCloudflare Developers
Created by PneuTueur on 8/17/2024 in #workers-help
Send a request to my worker's endpoint from a cron trigger event?
So I set up a cron trigger that should send a request every 15 minutes to one of my worker's routes using fetch with await keyword. However, it seems that the request is never sent (the operation expected is not performed) while it succeeds when I use the Javascript console of any browser.
7 replies
CDCloudflare Developers
Created by PneuTueur on 8/9/2024 in #workers-help
Access D1 database outside a request
Hello, I am trying to configure a D1 database for my Cloudflare worker. I have already created the database and added it to
wrangler.toml
wrangler.toml
. In the docs (https://developers.cloudflare.com/d1/get-started/), they say we can access the database like this:
export interface Env {
// If you set another name in wrangler.toml as the value for 'binding',
// replace "DB" with the variable name you defined.
DB: D1Database;
}

export default {
async fetch(request, env): Promise<Response> {
const { pathname } = new URL(request.url);

if (pathname === "/api/beverages") {
// If you did not use `DB` as your binding name, change it here
const { results } = await env.DB.prepare(
"SELECT * FROM Customers WHERE CompanyName = ?"
)
.bind("Bs Beverages")
.all();
return Response.json(results);
}

return new Response(
"Call /api/beverages to see everyone who works at Bs Beverages"
);
},
} satisfies ExportedHandler<Env>;
export interface Env {
// If you set another name in wrangler.toml as the value for 'binding',
// replace "DB" with the variable name you defined.
DB: D1Database;
}

export default {
async fetch(request, env): Promise<Response> {
const { pathname } = new URL(request.url);

if (pathname === "/api/beverages") {
// If you did not use `DB` as your binding name, change it here
const { results } = await env.DB.prepare(
"SELECT * FROM Customers WHERE CompanyName = ?"
)
.bind("Bs Beverages")
.all();
return Response.json(results);
}

return new Response(
"Call /api/beverages to see everyone who works at Bs Beverages"
);
},
} satisfies ExportedHandler<Env>;
Well, that's great, but how can I read the database content within a function which is not related to a request and does not have a prebuilt
env
env
parameter?
18 replies
CDCloudflare Developers
Created by PneuTueur on 7/26/2024 in #workers-help
Deploying a worker based on an existing Node project
Hello, Let's assume that I have a working Node.js/Express/TS local server with node modules installed, source code, public files, data files, etc. Is there a way I can add wrangler to it, even by modifying the files, without restarting from the beginning? I didn't see any instructions on how to use wrangler with an already existing project in the docs. Please tell me if I am wrong.
1 replies
CDCloudflare Developers
Created by PneuTueur on 5/5/2024 in #general-help
Worker unreachable from my IP only
Hello, I published a worker today and to my surprise my browser says ‘Site unreachable / DNS not found’ when I try to access it from my IP. However, when I use a VPN, I no longer have any problems... Why this unexpected behaviour? Apparently I'm not the first person to experience this kind of problem: see https://community.cloudflare.com/t/worker-published-but-not-reachable-or-not-responding/119986/2
3 replies