Unsmart | Tech debt
04/28/2023, 4:03 AMbret_pat
04/28/2023, 4:05 AMbret_pat
04/28/2023, 4:07 AMbret_pat
04/28/2023, 4:07 AMAkarys
04/29/2023, 6:44 PMhttps://dash.cloudflare.com/$id/workers/overview?enable-durable-objects
, except that doesn't bring up any modal or anythingAkarys
04/29/2023, 6:44 PMJames
04/29/2023, 6:57 PMsathoro
05/01/2023, 4:11 AMStarlin
05/02/2023, 4:52 AM[durable_objects]
bindings = [{name = "COUNTER1", class_name = "Counter"}]
durable object reference:
let id = env.COUNTER1.idFromName(requestIp);
let obj = env.COUNTER1.get(id);
let resp = await obj.fetch(request.url);
let count = parseInt(await resp.text())
Durable object class:
export class Counter {
state: any;
constructor(state:any) {
this.state = state;
}
async fetch(request:any) {
// Apply requested action.
let url = new URL(request.url);
let value = await this.state.storage.get("value") || 0;
++value;
await this.state.storage.put("value", value);
return new Response(value);
}
}
binding.ts:
COUNTER1: DurableObjectNamespace;
Error after deploying using wrangler publish:
✘ [ERROR] TypeError: Cannot read properties of undefined (reading 'idFromName')
can someone help here?HardAtWork
05/02/2023, 6:14 AMStarlin
05/02/2023, 6:43 AMDani Foldi
05/02/2023, 6:56 AMmigrations
entry that you need when you define, rename or remove a DO class
Add this to the end of wrangler.toml:
toml
[[migrations]]
tag = ''
new_classes = ['Counter']
Starlin
05/02/2023, 7:36 AM✘ [ERROR] TypeError: Cannot read properties of undefined (reading 'idFromName')
Dani Foldi
05/02/2023, 7:37 AMStarlin
05/02/2023, 7:40 AMpublic static async processRequest(request: Request, env: Bindings): Promise<Response> {
const requestIp:string | null = request.headers.get('CF-Connecting-IP');
const requestUrl:string = request.url;
//const list = await env.test_kv_binding.list({});
if(requestIp && requestUrl.includes("test url")) {
if(requestIp) {
let id = env.COUNTER1.idFromName(requestIp); //facing error here
let obj = env.COUNTER1.get(id);
let resp = await obj.fetch(request.url);
let count = parseInt(await resp.text())
console.log('count : ', count);
}
}
binding.ts:
interface Bindings {
COUNTER1: DurableObjectNamespace;
}
index.ts
import { RequestDomain } from './request/request.domain';
export async function handleRequest(request: Request, env: Bindings) {
return await RequestDomain.processRequest(request, env);
}
export class Counter {
state: any;
constructor(state:any) {
this.state = state;
}
async fetch(request:any) {
let url = new URL(request.url);
let value = await this.state.storage.get("value") || 0;
++value;
await this.state.storage.put("value", value);
return new Response(value);
}
}
const worker: ExportedHandler<Bindings> = { fetch: handleRequest };
export default worker;
Dani Foldi
05/02/2023, 7:48 AMStarlin
05/02/2023, 7:54 AMDani Foldi
05/02/2023, 8:05 AM--environment prod
, for example, when deploying)Starlin
05/02/2023, 8:10 AMDani Foldi
05/02/2023, 8:11 AMdurable_objects.bindings = []
under the env definition? Bindings don't get inheritedStarlin
05/02/2023, 8:12 AMDani Foldi
05/02/2023, 8:13 AMDani Foldi
05/02/2023, 8:14 AMdurable_objects.bindings
instead of bindings
Starlin
05/02/2023, 8:16 AMDani Foldi
05/02/2023, 8:17 AMsathoro
05/02/2023, 2:57 PMUnsmart | Tech debt
05/02/2023, 2:57 PMUnsmart | Tech debt
05/02/2023, 2:57 PMsathoro
05/02/2023, 3:00 PMjs
console.log("SIZE", JSON.stringify(await queueStub.toJSON()).length);
output: SIZE 134275
shouldn't be possible, right? that is using itty-durable which stores the whole value in a single "field"