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!'));
Was this page helpful?