Shravan
Shravan
CDCloudflare Developers
Created by Shravan on 11/6/2023 in #workers-help
Trying to get access to bindings in a function that's called by hono
I wanted to know if the below was bad practice
export type Bindings = {
// Example binding to KV. Learn more at https://developers.cloudflare.com/workers/runtime-apis/kv/
INNGEST_WORKFLOW_PERSISTANCE_KV: KVNamespace;
// DATABASE: D1Database;

//
// Example binding to Durable Object. Learn more at https://developers.cloudflare.com/workers/runtime-apis/durable-objects/
// MY_DURABLE_OBJECT: DurableObjectNamespace;
//
// Example binding to R2. Learn more at https://developers.cloudflare.com/workers/runtime-apis/r2/
// MY_BUCKET: R2Bucket;
//
// Example binding to a Service. Learn more at https://developers.cloudflare.com/workers/runtime-apis/service-bindings/
// MY_SERVICE: Fetcher;
//
// Example binding to a Queue. Learn more at https://developers.cloudflare.com/queues/javascript-apis/
// MY_QUEUE: Queue;
// AI: any;
// VECTOR_INDEX: VectorizeIndex;
};

declare global {
export interface BINDINGS extends Bindings {}
// eslint-disable-next-line no-var
var BINDINGS: BINDINGS;
}

const app = new Hono<{ Bindings: Bindings }>();

app.use('*', async (c, next) => {
try {
console.log('hello');
globalThis.BINDINGS = c.env;
await next();
} catch (e) {
console.log(e);
}
});

app.get('/', (c) => c.text('Hello Hono!'));
export type Bindings = {
// Example binding to KV. Learn more at https://developers.cloudflare.com/workers/runtime-apis/kv/
INNGEST_WORKFLOW_PERSISTANCE_KV: KVNamespace;
// DATABASE: D1Database;

//
// Example binding to Durable Object. Learn more at https://developers.cloudflare.com/workers/runtime-apis/durable-objects/
// MY_DURABLE_OBJECT: DurableObjectNamespace;
//
// Example binding to R2. Learn more at https://developers.cloudflare.com/workers/runtime-apis/r2/
// MY_BUCKET: R2Bucket;
//
// Example binding to a Service. Learn more at https://developers.cloudflare.com/workers/runtime-apis/service-bindings/
// MY_SERVICE: Fetcher;
//
// Example binding to a Queue. Learn more at https://developers.cloudflare.com/queues/javascript-apis/
// MY_QUEUE: Queue;
// AI: any;
// VECTOR_INDEX: VectorizeIndex;
};

declare global {
export interface BINDINGS extends Bindings {}
// eslint-disable-next-line no-var
var BINDINGS: BINDINGS;
}

const app = new Hono<{ Bindings: Bindings }>();

app.use('*', async (c, next) => {
try {
console.log('hello');
globalThis.BINDINGS = c.env;
await next();
} catch (e) {
console.log(e);
}
});

app.get('/', (c) => c.text('Hello Hono!'));
5 replies
CDCloudflare Developers
Created by Shravan on 11/6/2023 in #general-help
Trying to get access to bindings in a function that's called by hono
I wanted to know if the below was bad practice
export type Bindings = {
// Example binding to KV. Learn more at https://developers.cloudflare.com/workers/runtime-apis/kv/
INNGEST_WORKFLOW_PERSISTANCE_KV: KVNamespace;
// DATABASE: D1Database;

//
// Example binding to Durable Object. Learn more at https://developers.cloudflare.com/workers/runtime-apis/durable-objects/
// MY_DURABLE_OBJECT: DurableObjectNamespace;
//
// Example binding to R2. Learn more at https://developers.cloudflare.com/workers/runtime-apis/r2/
// MY_BUCKET: R2Bucket;
//
// Example binding to a Service. Learn more at https://developers.cloudflare.com/workers/runtime-apis/service-bindings/
// MY_SERVICE: Fetcher;
//
// Example binding to a Queue. Learn more at https://developers.cloudflare.com/queues/javascript-apis/
// MY_QUEUE: Queue;
// AI: any;
// VECTOR_INDEX: VectorizeIndex;
};

declare global {
export interface BINDINGS extends Bindings {}
// eslint-disable-next-line no-var
var BINDINGS: BINDINGS;
}

const app = new Hono<{ Bindings: Bindings }>();

app.use('*', async (c, next) => {
try {
console.log('hello');
globalThis.BINDINGS = c.env;
await next();
} catch (e) {
console.log(e);
}
});

app.get('/', (c) => c.text('Hello Hono!'));
export type Bindings = {
// Example binding to KV. Learn more at https://developers.cloudflare.com/workers/runtime-apis/kv/
INNGEST_WORKFLOW_PERSISTANCE_KV: KVNamespace;
// DATABASE: D1Database;

//
// Example binding to Durable Object. Learn more at https://developers.cloudflare.com/workers/runtime-apis/durable-objects/
// MY_DURABLE_OBJECT: DurableObjectNamespace;
//
// Example binding to R2. Learn more at https://developers.cloudflare.com/workers/runtime-apis/r2/
// MY_BUCKET: R2Bucket;
//
// Example binding to a Service. Learn more at https://developers.cloudflare.com/workers/runtime-apis/service-bindings/
// MY_SERVICE: Fetcher;
//
// Example binding to a Queue. Learn more at https://developers.cloudflare.com/queues/javascript-apis/
// MY_QUEUE: Queue;
// AI: any;
// VECTOR_INDEX: VectorizeIndex;
};

declare global {
export interface BINDINGS extends Bindings {}
// eslint-disable-next-line no-var
var BINDINGS: BINDINGS;
}

const app = new Hono<{ Bindings: Bindings }>();

app.use('*', async (c, next) => {
try {
console.log('hello');
globalThis.BINDINGS = c.env;
await next();
} catch (e) {
console.log(e);
}
});

app.get('/', (c) => c.text('Hello Hono!'));
5 replies
CDCloudflare Developers
Created by Shravan on 10/24/2023 in #general-help
Does the new pricing model consider setTimeout as part of IO time?
With the new pricing model for workers: https://blog.cloudflare.com/workers-pricing-scale-to-zero/ Would the worker scale to zero with something like setTimeout just like it does io?
4 replies