yea a bit of a bummer, you can store data in R2 but then you would have to retrieve it each time bef
yea a bit of a bummer, you can store data in R2 but then you would have to retrieve it each time before it could be used



wrangler containers images listX
•11/15/25, 12:27 AM



X
•11/17/25, 3:30 PM
wrangler containers images listconst containerInstance = await getRandom(
env.API_CONTAINER,
INSTANCE_COUNT
);import { DurableObject } from 'cloudflare:workers';
export class ApiContainer extends DurableObject<Env> {
container: globalThis.Container;
monitor?: Promise<unknown>;
constructor(ctx: DurableObjectState, env: Env) {
super(ctx, env);
this.container = ctx.container!;
void this.ctx.blockConcurrencyWhile(async () => {
if (!this.container.running) this.container.start({
enableInternet: false,
workersAddress: '10.0.0.2:8080',
env: {
GOOGLE_CLIENT_ID: env.GOOGLE_CLIENT_ID
}
});
});
}
async fetch(req: Request) {
try {
return await this.container.getTcpPort(8080).fetch(req.url.replace('https:', 'http:'), req);
} catch (err: any) {
return new Response(`${this.ctx.id.toString()}: ${err.message}`, { status: 500 });
}
}
}
export default {
async fetch(request, env): Promise<Response> {
try {
return await env.API_CONTAINER.get(env.API_CONTAINER.idFromName(request.url)).fetch(request);
} catch (err: any) {
console.error('Error fetch:', err.message);
return new Response(err.message, { status: 500 });
}
},
} satisfies ExportedHandler<Env>;override async onContainerRequest(request: Request) {
// call KV, R2, etc if path starts with /cfservices
}