@jakuta-inc/worker-proxy 3.0.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export type { VentureProxyConfig, CentralAdminProxyConfig, ProxyOutcome, ProxyHandler, ProxyError } from "./same-origin-proxy.js";
2
- export { ADMIN_API_BASE, createVentureProxyHandler, createCentralAdminProxyHandler } from "./same-origin-proxy.js";
1
+ export type { Backend, PathRewrite, Route, HealthProbeResult, ProxyHealthCheck, ProxyHandlerConfig, ProxyOutcome, ProxyHandler, ProxyError, } from "./same-origin-proxy.js";
2
+ export { ADMIN_API_BASE, createProxyHandler, createAdminAuthRoute, } from "./same-origin-proxy.js";
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAClI,OAAO,EAAE,cAAc,EAAE,yBAAyB,EAAE,8BAA8B,EAAE,MAAM,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,OAAO,EACP,WAAW,EACX,KAAK,EACL,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,UAAU,GACX,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,wBAAwB,CAAC"}
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { ADMIN_API_BASE, createVentureProxyHandler, createCentralAdminProxyHandler } from "./same-origin-proxy.js";
1
+ export { ADMIN_API_BASE, createProxyHandler, createAdminAuthRoute, } from "./same-origin-proxy.js";
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,yBAAyB,EAAE,8BAA8B,EAAE,MAAM,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,wBAAwB,CAAC"}
@@ -1,20 +1,107 @@
1
1
  export declare const ADMIN_API_BASE = "https://jakuta-admin-api.fly.dev";
2
+ interface BackendBase {
3
+ readonly base: string;
4
+ }
5
+ /**
6
+ * A backend identity. The `kind` discriminant determines the cookie-transform
7
+ * policy applied when forwarding a request to this backend:
8
+ *
9
+ * - `"admin"` — the admin backend owns the `admin_session` cookie, so the
10
+ * inbound `Cookie` header is preserved verbatim on the outbound hop. Any
11
+ * inbound `X-Admin-Session` header is stripped first, because that header
12
+ * is a proxy-internal trust boundary and a client that sets it is
13
+ * attempting forgery.
14
+ * - `"venture"` — a venture backend must never see the raw `admin_session`
15
+ * cookie. The proxy deletes the `Cookie` header and, if an `admin_session`
16
+ * was present, injects `X-Admin-Session: <session_id>` carrying the raw
17
+ * session id for `admin-client`'s `extract_session_from_handoff_header`.
18
+ * Any inbound `X-Admin-Session` header is stripped first (forgery defense).
19
+ *
20
+ * Cookie-transform semantics are an attribute of the Backend, not of the
21
+ * Route. There is no per-route override. Any caller that could point a route
22
+ * at the admin backend while running the venture cookie-stripping transform
23
+ * would break web session restore on admin-api; attaching the transform to
24
+ * backend identity makes that state unrepresentable.
25
+ */
26
+ export type Backend = (BackendBase & {
27
+ readonly kind: "admin";
28
+ }) | (BackendBase & {
29
+ readonly kind: "venture";
30
+ });
31
+ /**
32
+ * A path-rewrite policy applied to the incoming pathname before forwarding.
33
+ * Either an identity passthrough or an explicit transform function. Encoded
34
+ * as a discriminated union so `createProxyHandler` callers cannot omit the
35
+ * decision — every Route states its rewrite policy explicitly.
36
+ */
37
+ export type PathRewrite = {
38
+ readonly kind: "identity";
39
+ } | {
40
+ readonly kind: "transform";
41
+ readonly apply: (incomingPath: string) => string;
42
+ };
2
43
  /**
3
- * @field ventureApiBase - Origin of the venture's Fly.io backend (e.g. "https://venoble-backend.fly.dev")
4
- * @field adminApiBase - Origin of the jakuta-admin API on Fly.io (e.g. "https://jakuta-admin-api.fly.dev")
44
+ * A single proxy route. Matched by `pathPrefix` as exact-equal OR
45
+ * prefix-followed-by-slash (so `/api` matches `/api` and `/api/foo` but not
46
+ * `/apiary`). First match in the route list wins.
47
+ *
48
+ * @field pathPrefix - Path prefix to match against the incoming request pathname
49
+ * @field target - Backend to forward matched requests to
50
+ * @field rewrite - Path rewrite policy applied before forwarding
51
+ */
52
+ export interface Route {
53
+ readonly pathPrefix: string;
54
+ readonly target: Backend;
55
+ readonly rewrite: PathRewrite;
56
+ }
57
+ /**
58
+ * Result of probing a backend's `/health` endpoint.
59
+ *
60
+ * @field status - `"ok"` if the backend responded with a 2xx, `"error"` on non-2xx or network failure
61
+ * @field probeUrl - The full URL that was probed, useful for error reporting
5
62
  */
6
- export interface VentureProxyConfig {
7
- ventureApiBase: string;
8
- adminApiBase: string;
63
+ export interface HealthProbeResult {
64
+ readonly status: "ok" | "error";
65
+ readonly probeUrl: string;
9
66
  }
10
67
  /**
11
- * @field adminApiBase - Origin of the jakuta-admin API on Fly.io. The central
12
- * admin frontend has no venture backend /api/* resolves to the admin API
13
- * directly.
68
+ * Health-check hook configuration. The unified proxy handler probes every
69
+ * backend in `probeTargets` in parallel and hands the results to
70
+ * `buildHealthResponse`, which is responsible for shaping the final response
71
+ * JSON and status code. Different frontends want different health payload
72
+ * shapes — the venture frontend reports both venture and admin, the central
73
+ * admin frontend reports admin only — so the handler does not hardcode a
74
+ * shape.
75
+ *
76
+ * The `results` map is keyed by backend kind (`"admin"` or `"venture"`). A
77
+ * `probeTargets` list that contains two backends of the same kind will have
78
+ * the later probe overwrite the earlier one in the map — do not pass
79
+ * duplicates.
14
80
  */
15
- export interface CentralAdminProxyConfig {
16
- adminApiBase: string;
81
+ export type ProxyHealthCheck = {
82
+ readonly kind: "disabled";
83
+ } | {
84
+ readonly kind: "enabled";
85
+ readonly path: string;
86
+ readonly probeTargets: readonly Backend[];
87
+ readonly buildHealthResponse: (results: Record<string, HealthProbeResult>) => Response;
88
+ };
89
+ /**
90
+ * Declarative configuration for `createProxyHandler`.
91
+ *
92
+ * @field routes - Ordered list of routes; first match wins
93
+ * @field healthCheck - Health-check hook configuration (use `{ kind: "disabled" }` to skip)
94
+ */
95
+ export interface ProxyHandlerConfig {
96
+ readonly routes: readonly Route[];
97
+ readonly healthCheck: ProxyHealthCheck;
17
98
  }
99
+ /**
100
+ * Outcome of `ProxyHandler.handleRequest`. Either the request was proxied
101
+ * (in which case the caller should return `proxiedResponse` to the client)
102
+ * or it was not matched by any route (in which case the caller should fall
103
+ * through to its next handler, typically OpenNext/Next.js).
104
+ */
18
105
  export type ProxyOutcome = {
19
106
  readonly proxied: true;
20
107
  readonly proxiedResponse: Response;
@@ -22,42 +109,54 @@ export type ProxyOutcome = {
22
109
  readonly proxied: false;
23
110
  };
24
111
  /**
112
+ * A structured proxy-internal error surfaced as a JSON 502 to the client.
113
+ *
25
114
  * @field kind - Discriminant tag for the error variant
26
115
  * @field target - Full URL that the proxy attempted to reach
27
- * @field backendName - Which backend was unreachable
116
+ * @field backendKind - Kind of backend that was unreachable
28
117
  */
29
- export type ProxyError = {
30
- kind: "backend_unreachable";
31
- target: string;
32
- backendName: "venture" | "admin";
33
- };
118
+ export interface ProxyError {
119
+ readonly kind: "backend_unreachable";
120
+ readonly target: string;
121
+ readonly backendKind: Backend["kind"];
122
+ }
34
123
  /**
124
+ * The public proxy interface. Built by `createProxyHandler`.
125
+ *
35
126
  * @field handleRequest - Route an incoming worker request through the proxy, returning a proxied response or fall-through signal
36
127
  */
37
128
  export interface ProxyHandler {
38
129
  handleRequest(workerRequest: Request): Promise<ProxyOutcome>;
39
130
  }
40
131
  /**
41
- * Venture frontend proxy handler. Routes `/api/*` to the venture's own
42
- * backend (stripping the `admin_session` cookie so it never leaks to the
43
- * venture backend) and `/auth/*` to the admin backend (rewriting `/auth/*`
44
- * to `/api/auth/*`). This is the correct handler for every venture
45
- * frontend.
132
+ * Build a `Route` that proxies `/auth/*` to the admin backend's `/api/auth/*`
133
+ * surface with cookies preserved. Every frontend that renders admin-shell's
134
+ * login UI needs this route, because admin-shell's `AdminRoute.*` constants
135
+ * (`/auth/login`, `/auth/logout`, `/auth/session`) are the single source of
136
+ * truth for the browser-facing path — the admin-api surface lives at
137
+ * `/api/auth/*`, and the rewrite connects the two.
138
+ *
139
+ * Spread the result into your `routes` array; do not hand-maintain the
140
+ * rewrite.
46
141
  *
47
- * @param proxyConfig - Backend origins to proxy to; bound once at Worker startup
48
- * @returns ProxyHandler that routes /api/*, /auth/*, and /_proxy/health requests
142
+ * @param adminBase - Origin of the jakuta-admin API (e.g. ADMIN_API_BASE)
143
+ * @returns A Route that matches `/auth` / `/auth/*` and forwards to `adminBase/api/auth/*`
49
144
  */
50
- export declare function createVentureProxyHandler(proxyConfig: VentureProxyConfig): ProxyHandler;
145
+ export declare function createAdminAuthRoute(adminBase: string): Route;
51
146
  /**
52
- * Central admin frontend proxy handler. Routes `/api/*` to the admin backend
53
- * with cookies preservedthe central admin frontend IS the admin frontend,
54
- * so its `admin_session` cookie must reach `jakuta-admin-api` unmodified.
55
- * Does NOT handle `/auth/*` because the central admin frontend calls
56
- * `/api/auth/*` directly; any `/auth/*` hit falls through to the Next.js
57
- * handler.
147
+ * Build a `ProxyHandler` from a declarative `ProxyHandlerConfig`. This is the
148
+ * single handler constructorthere is no separate venture or central-admin
149
+ * handler. Consumers express their routing topology as a list of
150
+ * `Route`s pointing at `Backend`s, and the handler dispatches by first-match.
151
+ *
152
+ * The cookie transform applied on each hop is determined by the target
153
+ * backend's `kind` (`"admin"` → preserve cookie, `"venture"` → cookie-to-header
154
+ * handoff). There is no per-route override. See the `Backend` doc comment for
155
+ * why this is unrepresentable state, not a missing feature.
58
156
  *
59
- * @param proxyConfig - Admin backend origin to proxy to; bound once at Worker startup
60
- * @returns ProxyHandler that routes /api/* and /_proxy/health requests
157
+ * @param config - Declarative route list and health-check hook
158
+ * @returns A ProxyHandler whose `handleRequest` dispatches the inbound request
61
159
  */
62
- export declare function createCentralAdminProxyHandler(proxyConfig: CentralAdminProxyConfig): ProxyHandler;
160
+ export declare function createProxyHandler(config: ProxyHandlerConfig): ProxyHandler;
161
+ export {};
63
162
  //# sourceMappingURL=same-origin-proxy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"same-origin-proxy.d.ts","sourceRoot":"","sources":["../src/same-origin-proxy.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,qCAAqC,CAAC;AAEjE;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACtC,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,MAAM,YAAY,GACpB;IAAE,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,eAAe,EAAE,QAAQ,CAAA;CAAE,GAC9D;IAAE,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAA;CAAE,CAAC;AAEhC;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,qBAAqB,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,SAAS,GAAG,OAAO,CAAC;CAClC,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,aAAa,CAAC,aAAa,EAAE,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CAC9D;AAkGD;;;;;;;;;GASG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{
25
- const stripped = new Headers(original);
26
- stripped.delete("cookie");
24
+ const ADMIN_SESSION_COOKIE_NAME = "admin_session";
25
+ const ADMIN_SESSION_HANDOFF_HEADER = "X-Admin-Session";
26
+ function findAdminSessionCookieValue(cookieHeader) {
27
+ const prefix = ADMIN_SESSION_COOKIE_NAME + "=";
28
+ for (const cookieSegment of cookieHeader.split(";")) {
29
+ const trimmed = cookieSegment.trim();
30
+ if (trimmed.startsWith(prefix)) {
31
+ return { kind: "found", sessionValue: trimmed.slice(prefix.length) };
32
+ }
33
+ }
34
+ return { kind: "absent" };
35
+ }
36
+ function readCookieHeader(headers) {
37
+ const value = headers.get("cookie");
38
+ if (value === null) {
39
+ return { kind: "absent" };
40
+ }
41
+ return { kind: "present", value };
42
+ }
43
+ function buildVentureForwardedHeaders(originalHeaders) {
44
+ const forwarded = new Headers(originalHeaders);
45
+ forwarded.delete(ADMIN_SESSION_HANDOFF_HEADER);
46
+ const cookieLookup = readCookieHeader(forwarded);
47
+ forwarded.delete("cookie");
48
+ if (cookieLookup.kind === "present") {
49
+ const sessionLookup = findAdminSessionCookieValue(cookieLookup.value);
50
+ if (sessionLookup.kind === "found") {
51
+ forwarded.set(ADMIN_SESSION_HANDOFF_HEADER, sessionLookup.sessionValue);
52
+ }
53
+ }
54
+ return forwarded;
55
+ }
56
+ function stripInboundHandoffHeader(originalHeaders) {
57
+ const stripped = new Headers(originalHeaders);
58
+ stripped.delete(ADMIN_SESSION_HANDOFF_HEADER);
27
59
  return stripped;
28
60
  }
29
61
  async function forwardToBackend(forwardInput) {
30
- const targetUrl = new URL(forwardInput.targetPath + forwardInput.originalUrl.search, forwardInput.targetBase);
31
- const forwardedHeaders = forwardInput.backendName === "venture"
32
- ? stripCookieHeader(forwardInput.originalRequest.headers)
33
- : forwardInput.originalRequest.headers;
62
+ const target = forwardInput.target;
63
+ const targetUrl = new URL(forwardInput.targetPath + forwardInput.originalUrl.search, target.base);
64
+ const forwardedHeaders = target.kind === "venture"
65
+ ? buildVentureForwardedHeaders(forwardInput.originalRequest.headers)
66
+ : stripInboundHandoffHeader(forwardInput.originalRequest.headers);
34
67
  try {
35
68
  return await fetch(new Request(targetUrl, {
36
69
  method: forwardInput.originalRequest.method,
@@ -43,109 +76,142 @@ async function forwardToBackend(forwardInput) {
43
76
  const proxyError = {
44
77
  kind: "backend_unreachable",
45
78
  target: targetUrl.toString(),
46
- backendName: forwardInput.backendName,
79
+ backendKind: target.kind,
47
80
  };
48
81
  return jsonErrorResponse({
49
82
  httpStatus: 502,
50
83
  errorBody: {
51
84
  error: proxyError.kind,
52
85
  target: proxyError.target,
53
- backend: proxyError.backendName,
54
- message: `Proxy couldn't reach the ${proxyError.backendName} backend at ${proxyError.target}. Check /_proxy/health to verify both backends are reachable.`,
86
+ backend: proxyError.backendKind,
87
+ message: `Proxy couldn't reach the ${proxyError.backendKind} backend at ${proxyError.target}. Check the configured health path to verify the backend is reachable.`,
55
88
  },
56
89
  });
57
90
  }
58
91
  }
92
+ function matchPathPrefix(params) {
93
+ if (params.pathname === params.prefix) {
94
+ return { kind: "match" };
95
+ }
96
+ if (params.pathname.startsWith(params.prefix + "/")) {
97
+ return { kind: "match" };
98
+ }
99
+ return { kind: "no_match" };
100
+ }
101
+ function assertNeverPathRewrite(rewrite) {
102
+ throw new Error(`unreachable PathRewrite variant: ${JSON.stringify(rewrite)}`);
103
+ }
104
+ function applyPathRewrite(params) {
105
+ switch (params.rewrite.kind) {
106
+ case "identity":
107
+ return params.incomingPath;
108
+ case "transform":
109
+ return params.rewrite.apply(params.incomingPath);
110
+ default:
111
+ return assertNeverPathRewrite(params.rewrite);
112
+ }
113
+ }
114
+ function normalizeBackend(backend) {
115
+ return { kind: backend.kind, base: stripTrailingSlash(backend.base) };
116
+ }
117
+ function normalizeRoute(route) {
118
+ return {
119
+ pathPrefix: route.pathPrefix,
120
+ target: normalizeBackend(route.target),
121
+ rewrite: route.rewrite,
122
+ };
123
+ }
124
+ function assertNeverHealthCheck(healthCheck) {
125
+ throw new Error(`unreachable ProxyHealthCheck variant: ${JSON.stringify(healthCheck)}`);
126
+ }
127
+ function normalizeHealthCheck(healthCheck) {
128
+ switch (healthCheck.kind) {
129
+ case "disabled":
130
+ return healthCheck;
131
+ case "enabled":
132
+ return {
133
+ kind: "enabled",
134
+ path: healthCheck.path,
135
+ probeTargets: healthCheck.probeTargets.map(normalizeBackend),
136
+ buildHealthResponse: healthCheck.buildHealthResponse,
137
+ };
138
+ default:
139
+ return assertNeverHealthCheck(healthCheck);
140
+ }
141
+ }
59
142
  /**
60
- * Venture frontend proxy handler. Routes `/api/*` to the venture's own
61
- * backend (stripping the `admin_session` cookie so it never leaks to the
62
- * venture backend) and `/auth/*` to the admin backend (rewriting `/auth/*`
63
- * to `/api/auth/*`). This is the correct handler for every venture
64
- * frontend.
143
+ * Build a `Route` that proxies `/auth/*` to the admin backend's `/api/auth/*`
144
+ * surface with cookies preserved. Every frontend that renders admin-shell's
145
+ * login UI needs this route, because admin-shell's `AdminRoute.*` constants
146
+ * (`/auth/login`, `/auth/logout`, `/auth/session`) are the single source of
147
+ * truth for the browser-facing path — the admin-api surface lives at
148
+ * `/api/auth/*`, and the rewrite connects the two.
149
+ *
150
+ * Spread the result into your `routes` array; do not hand-maintain the
151
+ * rewrite.
65
152
  *
66
- * @param proxyConfig - Backend origins to proxy to; bound once at Worker startup
67
- * @returns ProxyHandler that routes /api/*, /auth/*, and /_proxy/health requests
153
+ * @param adminBase - Origin of the jakuta-admin API (e.g. ADMIN_API_BASE)
154
+ * @returns A Route that matches `/auth` / `/auth/*` and forwards to `adminBase/api/auth/*`
68
155
  */
69
- export function createVentureProxyHandler(proxyConfig) {
70
- const ventureBase = stripTrailingSlash(proxyConfig.ventureApiBase);
71
- const adminBase = stripTrailingSlash(proxyConfig.adminApiBase);
156
+ export function createAdminAuthRoute(adminBase) {
72
157
  return {
73
- async handleRequest(workerRequest) {
74
- const requestUrl = new URL(workerRequest.url);
75
- const pathname = requestUrl.pathname;
76
- if (pathname === "/_proxy/health") {
77
- const [venture, admin] = await Promise.all([
78
- probeHealth(ventureBase),
79
- probeHealth(adminBase),
80
- ]);
81
- const healthStatus = { venture, admin };
82
- const allOk = venture.status === "ok" && admin.status === "ok";
83
- const proxiedResponse = new Response(JSON.stringify(healthStatus), {
84
- status: allOk ? 200 : 503,
85
- headers: { "content-type": "application/json" },
86
- });
87
- return { proxied: true, proxiedResponse };
88
- }
89
- if (pathname === "/api" || pathname.startsWith("/api/")) {
90
- const proxiedResponse = await forwardToBackend({
91
- originalRequest: workerRequest,
92
- originalUrl: requestUrl,
93
- targetBase: ventureBase,
94
- targetPath: pathname,
95
- backendName: "venture",
96
- });
97
- return { proxied: true, proxiedResponse };
98
- }
99
- if (pathname === "/auth" || pathname.startsWith("/auth/")) {
100
- const adminPath = "/api" + pathname;
101
- const proxiedResponse = await forwardToBackend({
102
- originalRequest: workerRequest,
103
- originalUrl: requestUrl,
104
- targetBase: adminBase,
105
- targetPath: adminPath,
106
- backendName: "admin",
107
- });
108
- return { proxied: true, proxiedResponse };
109
- }
110
- return { proxied: false };
158
+ pathPrefix: "/auth",
159
+ target: { kind: "admin", base: stripTrailingSlash(adminBase) },
160
+ rewrite: {
161
+ kind: "transform",
162
+ apply: (incomingPath) => "/api" + incomingPath,
111
163
  },
112
164
  };
113
165
  }
114
166
  /**
115
- * Central admin frontend proxy handler. Routes `/api/*` to the admin backend
116
- * with cookies preservedthe central admin frontend IS the admin frontend,
117
- * so its `admin_session` cookie must reach `jakuta-admin-api` unmodified.
118
- * Does NOT handle `/auth/*` because the central admin frontend calls
119
- * `/api/auth/*` directly; any `/auth/*` hit falls through to the Next.js
120
- * handler.
167
+ * Build a `ProxyHandler` from a declarative `ProxyHandlerConfig`. This is the
168
+ * single handler constructorthere is no separate venture or central-admin
169
+ * handler. Consumers express their routing topology as a list of
170
+ * `Route`s pointing at `Backend`s, and the handler dispatches by first-match.
121
171
  *
122
- * @param proxyConfig - Admin backend origin to proxy to; bound once at Worker startup
123
- * @returns ProxyHandler that routes /api/* and /_proxy/health requests
172
+ * The cookie transform applied on each hop is determined by the target
173
+ * backend's `kind` (`"admin"` preserve cookie, `"venture"` → cookie-to-header
174
+ * handoff). There is no per-route override. See the `Backend` doc comment for
175
+ * why this is unrepresentable state, not a missing feature.
176
+ *
177
+ * @param config - Declarative route list and health-check hook
178
+ * @returns A ProxyHandler whose `handleRequest` dispatches the inbound request
124
179
  */
125
- export function createCentralAdminProxyHandler(proxyConfig) {
126
- const adminBase = stripTrailingSlash(proxyConfig.adminApiBase);
180
+ export function createProxyHandler(config) {
181
+ const normalizedRoutes = config.routes.map(normalizeRoute);
182
+ const normalizedHealthCheck = normalizeHealthCheck(config.healthCheck);
127
183
  return {
128
184
  async handleRequest(workerRequest) {
129
185
  const requestUrl = new URL(workerRequest.url);
130
186
  const pathname = requestUrl.pathname;
131
- if (pathname === "/_proxy/health") {
132
- const admin = await probeHealth(adminBase);
133
- const healthStatus = { admin };
134
- const proxiedResponse = new Response(JSON.stringify(healthStatus), {
135
- status: admin.status === "ok" ? 200 : 503,
136
- headers: { "content-type": "application/json" },
137
- });
187
+ if (normalizedHealthCheck.kind === "enabled" &&
188
+ pathname === normalizedHealthCheck.path) {
189
+ const probeResults = await Promise.all(normalizedHealthCheck.probeTargets.map(async (backend) => {
190
+ const result = await probeHealth(backend.base);
191
+ return [backend.kind, result];
192
+ }));
193
+ const resultsByKind = {};
194
+ for (const [kind, result] of probeResults) {
195
+ resultsByKind[kind] = result;
196
+ }
197
+ const proxiedResponse = normalizedHealthCheck.buildHealthResponse(resultsByKind);
138
198
  return { proxied: true, proxiedResponse };
139
199
  }
140
- if (pathname === "/api" || pathname.startsWith("/api/")) {
141
- const proxiedResponse = await forwardToBackend({
142
- originalRequest: workerRequest,
143
- originalUrl: requestUrl,
144
- targetBase: adminBase,
145
- targetPath: pathname,
146
- backendName: "admin",
147
- });
148
- return { proxied: true, proxiedResponse };
200
+ for (const route of normalizedRoutes) {
201
+ const match = matchPathPrefix({ pathname, prefix: route.pathPrefix });
202
+ if (match.kind === "match") {
203
+ const rewrittenPath = applyPathRewrite({
204
+ rewrite: route.rewrite,
205
+ incomingPath: pathname,
206
+ });
207
+ const proxiedResponse = await forwardToBackend({
208
+ originalRequest: workerRequest,
209
+ originalUrl: requestUrl,
210
+ target: route.target,
211
+ targetPath: rewrittenPath,
212
+ });
213
+ return { proxied: true, proxiedResponse };
214
+ }
149
215
  }
150
216
  return { proxied: false };
151
217
  },
@@ -1 +1 @@
1
- {"version":3,"file":"same-origin-proxy.js","sourceRoot":"","sources":["../src/same-origin-proxy.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,kCAAkC,CAAC;AAwDjE,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAE/B,SAAS,kBAAkB,CAAC,SAAiB;IAC3C,OAAO,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACtE,CAAC;AAOD,SAAS,iBAAiB,CAAC,UAAkC;IAC3D,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE;QACxD,MAAM,EAAE,UAAU,CAAC,UAAU;QAC7B,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;KAChD,CAAC,CAAC;AACL,CAAC;AAED,KAAK,UAAU,WAAW,CAAC,OAAe;IACxC,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC;IACxD,IAAI,CAAC;QACH,MAAM,cAAc,GAAG,MAAM,KAAK,CAAC,QAAQ,EAAE;YAC3C,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,iBAAiB,CAAC;SAC/C,CAAC,CAAC;QACH,OAAO,EAAE,MAAM,EAAE,cAAc,CAAC,EA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/worker-proxy",
3
- "version": "3.0.0",
4
- "description": "Same-origin reverse proxy for Jakuta admin panel Cloudflare Workers",
5
- "type": "module",
6
- "main": "dist/index.js",
7
- "types": "dist/index.d.ts",
8
- "files": [
9
- "dist"
10
- ],
11
- "scripts": {
12
- "build": "tsc",
13
- "prepublishOnly": "tsc",
14
- "test": "vitest run"
15
- },
16
- "publishConfig": {
17
- "access": "restricted"
18
- },
19
- "repository": {
20
- "type": "git",
21
- "url": "https://github.com/Jakuta-Inc/jakuta-admin.git",
22
- "directory": "packages/worker-proxy"
23
- },
24
- "devDependencies": {
25
- "@cloudflare/workers-types": "^4.20250327.0",
26
- "typescript": "^5.7.0"
27
- }
28
- }
1
+ {
2
+ "name": "@jakuta-inc/worker-proxy",
3
+ "version": "5.0.0",
4
+ "description": "Same-origin reverse proxy for Jakuta admin panel Cloudflare Workers",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "prepublishOnly": "tsc",
14
+ "test": "vitest run"
15
+ },
16
+ "publishConfig": {
17
+ "access": "restricted"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/Jakuta-Inc/jakuta-admin.git",
22
+ "directory": "packages/worker-proxy"
23
+ },
24
+ "devDependencies": {
25
+ "@cloudflare/workers-types": "^4.20250327.0",
26
+ "typescript": "^5.7.0"
27
+ }
28
+ }