add connect func to RuntimeContext

This commit is contained in:
syumai 2023-06-25 18:03:36 +09:00
parent 3bff27df38
commit 3a421a2929

View File

@ -1,5 +1,6 @@
import "./polyfill_performance.js";
import "./wasm_exec.js";
import { connect } from 'cloudflare:sockets';
const go = new Go();
@ -18,19 +19,27 @@ async function run() {
await readyPromise;
}
function createRuntimeContext(env, ctx) {
return {
env,
ctx,
connect,
}
}
export async function fetch(req, env, ctx) {
await run();
return handleRequest(req, { env, ctx });
return handleRequest(req, createRuntimeContext(env, ctx));
}
export async function scheduled(event, env, ctx) {
await run();
return runScheduler(event, { env, ctx });
return runScheduler(event, createRuntimeContext(env, ctx));
}
// onRequest handles request to Cloudflare Pages
export async function onRequest(ctx) {
await run();
const { request, env } = ctx;
return handleRequest(request, { env, ctx });
return handleRequest(request, createRuntimeContext(env, ctx));
}