mirror of
https://github.com/syumai/workers.git
synced 2025-03-10 17:29:11 +00:00
add connect func to RuntimeContext
This commit is contained in:
parent
3bff27df38
commit
3a421a2929
@ -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));
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user