Skip to content
36 linesCodeBlameRaw
1// A service that is turned off on this installation.
2//
3// Self-hosted phase 1 runs the core forge only. The site and the services
4// still hold bindings to the cloud runner and the deployments' builders;
5// this Worker stands in for each of them: every method of the JSON protocol
6// the services speak (`POST /rpc/<method>`) answers with a failed Result
7// that says why, instead of failing.
8//
9// OFF_NAME names the feature in those messages, such as "Cloud runners".
10
11import { WorkerEntrypoint } from "cloudflare:workers";
12
13function off(env) {
14 const name = env.OFF_NAME ?? "This feature";
15 return {
16 ok: false,
17 error: { code: "forbidden", message: `${name} are off on this installation of g1t.` },
18 };
19}
20
21export default class Off extends WorkerEntrypoint {
22 // ── The JSON protocol ──
23 async fetch(request) {
24 const { pathname } = new URL(request.url);
25 if (request.method === "POST" && pathname.startsWith("/rpc/")) {
26 return Response.json(off(this.env));
27 }
28 return new Response("Off on this installation.", { status: 404 });
29 }
30
31 // Events and schedules for a service that is off are dropped.
32 async queue(batch) {
33 batch.ackAll();
34 }
35 async scheduled() {}
36}