Update Site source
This commit is contained in:
commit
9a4ce930c7
126 files changed
+25723
No files matched your search
@@ -0,0 +1,28 @@
|
||||
import handler from "vinext/server/fetch-handler";
|
||||
import { runWithConnectorBinding } from "../lib/connector-context";
|
||||
import type { ConnectorBinding } from "../lib/connector-contract.mjs";
|
||||
|
||||
export default {
|
||||
fetch(request: Request, env: Cloudflare.Env, ctx: ExecutionContext<{ CONNECTORS?: ConnectorBinding }>) {
|
||||
let binding = ctx.props?.CONNECTORS;
|
||||
// Local preview emulates the same request-scoped capability. This branch and
|
||||
// the auxiliary service binding are absent from production builds.
|
||||
if (import.meta.env.DEV && !binding && env.CONNECTORS) {
|
||||
const preview = env.CONNECTORS;
|
||||
const expiresAt = Date.now() + 60_000;
|
||||
binding = {
|
||||
async getContext() {
|
||||
if (Date.now() >= expiresAt) return { status: "request_context_expired" };
|
||||
return preview.getContext?.() ?? { status: "binding_unavailable" };
|
||||
},
|
||||
async invoke(connectorId, actionName, args) {
|
||||
if (Date.now() >= expiresAt) {
|
||||
return { status: "request_context_expired", message: "This request has expired. Please try again." };
|
||||
}
|
||||
return preview.invoke(connectorId, actionName, args);
|
||||
},
|
||||
};
|
||||
}
|
||||
return runWithConnectorBinding(binding, () => handler.fetch(request, env, ctx));
|
||||
},
|
||||
};
|
||||
Reference in new issue
Block a user