xeon06
xeon06
Explore posts from servers
CDCloudflare Developers
Created by xeon06 on 10/12/2024 in #workers-help
API to set worker environment variable?
Hey folks, I'm looking for an HTTP API to set a Worker's environment variable. Digging into Wrangler, another member of the community found this for secrets: /accounts/account_id/workers/scripts/script_name/secrets https://github.com/cloudflare/workers-sdk/blob/main/packages/wrangler/src/secret/index.ts#L170-L185 But I'm not sure if it can apply to regular plain text env vars, and am not finding anything else documented anywhere.
3 replies
CDCloudflare Developers
Created by xeon06 on 10/9/2024 in #workers-help
Service binding RPC method null
I have a project with a service binding I call like this:
const result = await ctx.runtime.env.CRYPTO.encrypt(arg)
const result = await ctx.runtime.env.CRYPTO.encrypt(arg)
Despite the service being bound correctly, I ge this in production:
TypeError: ctx.runtime.env.CRYPTO.encrypt is not a function
TypeError: ctx.runtime.env.CRYPTO.encrypt is not a function
Logging this
console.log(
ctx.runtime.env.CRYPTO.fetch,
typeof ctx.runtime.env.CRYPTO.fetch,
ctx.runtime.env.CRYPTO.encrypt,
typeof ctx.runtime.env.CRYPTO.encrypt,
)
console.log(
ctx.runtime.env.CRYPTO.fetch,
typeof ctx.runtime.env.CRYPTO.fetch,
ctx.runtime.env.CRYPTO.encrypt,
typeof ctx.runtime.env.CRYPTO.encrypt,
)
Gives
"function fetch() { [native code] }",
"function",
null,
"undefined"
"function fetch() { [native code] }",
"function",
null,
"undefined"
I can rewrite it using fetch, but are these supposed to work?
8 replies
CDCloudflare Developers
Created by xeon06 on 10/9/2024 in #pages-help
Debugging service binding
Hey folks, I have a service binding I call like this:
const result = await ctx.runtime.env.CRYPTO.encrypt(arg)
const result = await ctx.runtime.env.CRYPTO.encrypt(arg)
The service is bound on my pages project, but I get this:
TypeError: ctx.runtime.env.CRYPTO.encrypt is not a function
TypeError: ctx.runtime.env.CRYPTO.encrypt is not a function
I can confirm the encrypt method is on the class when I do edit code. I'm kind of at a loss for what else to try.
3 replies
CDCloudflare Developers
Created by xeon06 on 10/8/2024 in #workers-help
Set secrets via HTTP
Is there any way to set a worker secret via HTTP? I see there's something for Worker Platform but not finding much for workers except for the wrangler command, but I want to do it through code...
3 replies
CDCloudflare Developers
Created by xeon06 on 10/1/2024 in #workers-help
Durable opbject bindings?
Do durable objects need to be bound through the dashboard? There's a space for it, but I have no dur
1 replies
CDCloudflare Developers
Created by xeon06 on 9/7/2024 in #workers-help
Setting DO script_name only in dev?
Hey folks, in order to work with Durable Objects with getPlatformProxy, you must use a separate worker and script_name. That's all fine, but is there a way to ensure the script_name is only set in dev, since that seems to have an effect in prod too?
[durable_objects]
bindings = [
{ name = "DATA_NOTIFIER", class_name = "DataNotifier", script_name = "dev-data-notifier-worker" }
]
[durable_objects]
bindings = [
{ name = "DATA_NOTIFIER", class_name = "DataNotifier", script_name = "dev-data-notifier-worker" }
]
1 replies
CDCloudflare Developers
Created by xeon06 on 9/5/2024 in #workers-help
RPC dispose not available?
Hey folks, I'm calling an RPC worker locally from a Cloudflare Astro project, 11.0.4 on the CF Astro adapter, Wrangler 3.74.0 When I call an RPC method, I get this:
An RPC stub was not disposed properly. You must call dispose() on all stubs in order to let the other side know that you are no longer using them. You cannot rely on the garbage collector for this because it may take arbitrarily long before actually collecting unreachable objects. As a shortcut, calling dispose() on the result of an RPC call disposes all stubs within it.
However there is nothing on dispose or [Symbol.dispose] for me to call, both are undefined. Am I in version incompatibility hell?
2 replies
DTDrizzle Team
Created by xeon06 on 8/14/2024 in #help
D1 Blobs as ArrayBuffer?
Hey folks, I'm trying to store ArrayBuffers in D1 as Blobs. This Cloudflare page seems to indicate that D1 will automatically do the marshalling of blobs <> ArrayBuffers https://developers.cloudflare.com/d1/build-with-d1/d1-client-api/#type-conversion But I am just getting plain number arrays back unless I use a custom type:
export const arrayBuffer = (name: string) =>
customType<{ data: ArrayBuffer; driverData: number[] }>({
dataType: () => "blob",
toDriver: (value) => [...new Uint8Array(value)],
fromDriver: (value) => new Uint8Array([...value]).buffer,
})(name)
export const arrayBuffer = (name: string) =>
customType<{ data: ArrayBuffer; driverData: number[] }>({
dataType: () => "blob",
toDriver: (value) => [...new Uint8Array(value)],
fromDriver: (value) => new Uint8Array([...value]).buffer,
})(name)
It feels like doing this operation on every query will be slow, so I'm wondering if there's another way to get an ArrayBuffer out of this whole thing?
1 replies
CDCloudflare Developers
Created by xeon06 on 8/12/2024 in #workers-help
RPC + cron?
Hey folks, I'm trying to add RPC to a worker that already has a scheduled handler for cron. It looks like inheriting from WorkerEntrypoint messes up any other method such as scheduled..?
3 replies
HHono
Created by xeon06 on 7/31/2024 in #help
Using HonoX with React and react-three-fiber
Hey all, I think I may be attempting something a little too tricky. I'm trying to make a HonoX project with a client-only island that uses react-three-fiber. A base install gives this error when hitting the page:
module is not defined
at eval (/Users/alexturpin/src/project/node_modules/react-reconciler/constants.js:8:3)
at instantiateModule (file:///Users/alexturpin/src/project/node_modules/vite/dist/node/chunks/dep-mCdpKltl.js:52650:11
module is not defined
at eval (/Users/alexturpin/src/project/node_modules/react-reconciler/constants.js:8:3)
at instantiateModule (file:///Users/alexturpin/src/project/node_modules/vite/dist/node/chunks/dep-mCdpKltl.js:52650:11
Adding @react-three/fiber to ssr.external however then results in:
[vite] Error when evaluating SSR module /node_modules/honox/dist/server/index.js: failed to import "@react-three/fiber"
|- /Users/alexturpin/src/project/node_modules/@react-three/fiber/dist/react-three-fiber.esm.js:1
import { c as createEvents, e as extend, u as useMutableCallback, a as useIsomorphicLayoutEffect, b as createRoot, i as isRef, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from './index-99983b2d.esm.js';
^^^^^^

SyntaxError: Cannot use import statement outside a module
[vite] Error when evaluating SSR module /node_modules/honox/dist/server/index.js: failed to import "@react-three/fiber"
|- /Users/alexturpin/src/project/node_modules/@react-three/fiber/dist/react-three-fiber.esm.js:1
import { c as createEvents, e as extend, u as useMutableCallback, a as useIsomorphicLayoutEffect, b as createRoot, i as isRef, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from './index-99983b2d.esm.js';
^^^^^^

SyntaxError: Cannot use import statement outside a module
Seems like either won't work, anyone has an idea?
2 replies
CDCloudflare Developers
Created by xeon06 on 2/1/2024 in #workers-help
WebAssembly.instantiate(): Wasm code generation disallowed by embedder
Hey folks, I'm trying to get a Wasm library to work in a Pages function, but I'm having the hardest time instantiating it. At first I was fetching the .wasm binary to instantiate, but someone in #pages-help told me it had to be bundled within the _worker.js script. Okay, now it's a UInt8Array directly in the _worker.js script but I still get this error. Is there more information on how the wasm binary should be bundled? Is it a specific format that will make the CF worker accept it?
15 replies
CDCloudflare Developers
Created by xeon06 on 2/1/2024 in #pages-help
Deployment failure logs
No description
2 replies
CDCloudflare Developers
Created by xeon06 on 1/31/2024 in #pages-help
CompileError: WebAssembly.instantiate(): Wasm code generation disallowed by embedder
Hey folks, I'm trying to run a wasm file compiled by emscripten on CF workers. It's working fine locally, but when I try it in production I get:
failed to asynchronously prepare wasm: CompileError: WebAssembly.instantiate(): Wasm code generation disallowed by embedder
failed to asynchronously prepare wasm: CompileError: WebAssembly.instantiate(): Wasm code generation disallowed by embedder
This page seems to indicate that WebAssembly.instantiate should work, am I missing something? https://developers.cloudflare.com/workers/runtime-apis/webassembly/
13 replies
CDCloudflare Developers
Created by xeon06 on 1/15/2024 in #pages-help
Accessing assets from pages functions
Hey folks, I'm building an app on Pages using the CloudFlare Astro adapter. I'm trying to access some of my static assets in a function, but Astro.locals.runtime.env.ASSETS seems to be undefined, both in directory or advanced mode. Does anyone know if there's any extra bits of config I need to do or?
10 replies
DTDrizzle Team
Created by xeon06 on 1/12/2024 in #help
Update with inner join?
Hey folks, is it possible to do an update with an inner join in order to have more complicated filter logic, with values coming from other tables, for our where?
14 replies
DTDrizzle Team
Created by xeon06 on 1/9/2024 in #help
Shifted properties in join
I'm getting some very strange join behavior. This query:
const foreignExchangeTransactions = await db
.select()
.from(transactions)
.innerJoin(inboxes, eq(transactions.inboxId, inboxes.id))
const foreignExchangeTransactions = await db
.select()
.from(transactions)
.innerJoin(inboxes, eq(transactions.inboxId, inboxes.id))
Returns a proper transaction, but the inboxes object is completely out of whack, missing some properties but also a lot of the properties are shifted:
inboxes: {
id: 'ayrmg4fy63',
createdAt: 'Budget',
cuid: 'CAD',
name: 'America/Toronto',
currencyCode: 1
}
inboxes: {
id: 'ayrmg4fy63',
createdAt: 'Budget',
cuid: 'CAD',
name: 'America/Toronto',
currencyCode: 1
}
It should be:
id: 1,
createdAt: '2024-01-09',
name: 'Budget',
cuid: 'ayrmg4fy63',
timezone: 'America/Toronto',
currencyCode: 'CAD'
id: 1,
createdAt: '2024-01-09',
name: 'Budget',
cuid: 'ayrmg4fy63',
timezone: 'America/Toronto',
currencyCode: 'CAD'
Tried with one other table and same result as well, weird shifted properties in the joiend table
2 replies
DTDrizzle Team
Created by xeon06 on 1/9/2024 in #help
Select fields with the same name in two different tables in a join
Is it possible to select two fields of the same name, but from a different table, as part of a join? e.g.
db
.select({
inboxCurrencyCode: inboxes.currencyCode,
cardCurrencyCode: cards.currencyCode,
})
.from(transactions)
.leftJoin(inboxes, eq(transactions.inboxId, inboxes.id))
.leftJoin(cards, eq(transactions.cardId, cards.id))
db
.select({
inboxCurrencyCode: inboxes.currencyCode,
cardCurrencyCode: cards.currencyCode,
})
.from(transactions)
.leftJoin(inboxes, eq(transactions.inboxId, inboxes.id))
.leftJoin(cards, eq(transactions.cardId, cards.id))
As-is, it only ever gives me one of two currencyCode fields, even if they are technically renamed by the partial select
2 replies
DTDrizzle Team
Created by xeon06 on 1/3/2024 in #help
String default for integer timestamps?
Hey folks, I'm using Drizzle with SQLite on CloudFlare D1. Using the following column schema:
createdAt: integer("created_at", { mode: "timestamp" }).default(sql`CURRENT_TIMESTAMP`),
createdAt: integer("created_at", { mode: "timestamp" }).default(sql`CURRENT_TIMESTAMP`),
From the D1 database viewer I am seeing that Drizzle creates values that look like this 2024-01-03 03:55:45, whereas values inserted via direct SQL are integers properly e.g. 1703894400. In addition, the string values show up as NULL in Drizzle Studio. Could I be doing something wrong or have I encountered a bug?
9 replies
CDCloudflare Developers
Created by xeon06 on 12/18/2023 in #workers-help
Email worker inside of a pages repo?
Hey folks, I'm trying to develop something that uses both pages for deployment of a frontend / backend website, but also an email worker. I want to try to keep the code in the same repo, but I realize that it will need to be separate deployments on CloudFlare, since pages doesn't support email routing. Are there existing patterns to keep both my pages and my email worker's code in the same repo while still being able to deploy everything?
5 replies