mirror of
https://github.com/syumai/workers.git
synced 2025-03-11 01:39:11 +00:00
add connect func to RuntimeContext
This commit is contained in:
parent
688b4b731e
commit
39aecde5ab
@ -1,5 +1,6 @@
|
|||||||
import "./polyfill_performance.js";
|
import "./polyfill_performance.js";
|
||||||
import "./wasm_exec.js";
|
import "./wasm_exec.js";
|
||||||
|
import { connect } from 'cloudflare:sockets';
|
||||||
|
|
||||||
const go = new Go();
|
const go = new Go();
|
||||||
|
|
||||||
@ -18,19 +19,27 @@ async function run() {
|
|||||||
await readyPromise;
|
await readyPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createRuntimeContext(env, ctx) {
|
||||||
|
return {
|
||||||
|
env,
|
||||||
|
ctx,
|
||||||
|
connect,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function fetch(req, env, ctx) {
|
export async function fetch(req, env, ctx) {
|
||||||
await run();
|
await run();
|
||||||
return handleRequest(req, { env, ctx });
|
return handleRequest(req, createRuntimeContext(env, ctx));
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function scheduled(event, env, ctx) {
|
export async function scheduled(event, env, ctx) {
|
||||||
await run();
|
await run();
|
||||||
return runScheduler(event, { env, ctx });
|
return runScheduler(event, createRuntimeContext(env, ctx));
|
||||||
}
|
}
|
||||||
|
|
||||||
// onRequest handles request to Cloudflare Pages
|
// onRequest handles request to Cloudflare Pages
|
||||||
export async function onRequest(ctx) {
|
export async function onRequest(ctx) {
|
||||||
await run();
|
await run();
|
||||||
const { request, env } = ctx;
|
const { request, env } = ctx;
|
||||||
return handleRequest(request, { env, ctx });
|
return handleRequest(request, createRuntimeContext(env, ctx));
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user