@jakuta-inc/worker-proxy 5.0.1 → 6.0.1
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 +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/same-origin-proxy.d.ts +31 -7
- package/dist/same-origin-proxy.d.ts.map +1 -1
- package/dist/same-origin-proxy.js +78 -27
- package/dist/same-origin-proxy.js.map +1 -1
- package/dist/venture_api_route.d.ts +3 -3
- package/dist/venture_api_route.d.ts.map +1 -1
- package/dist/venture_api_route.js +4 -4
- package/dist/venture_api_route.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { Backend, PathRewrite, Route, HealthProbeResult, ProxyHealthCheck, ProxyHandlerConfig, ProxyOutcome, ProxyHandler, ProxyError
|
|
2
|
-
export {
|
|
3
|
-
export { VENTURE_API_PREFIX, createVentureApiRoute
|
|
1
|
+
export type { AllowedHosts, Backend, PathRewrite, Route, HealthProbeResult, ProxyHealthCheck, ProxyHandlerConfig, ProxyOutcome, ProxyHandler, ProxyError } from "./same-origin-proxy.js";
|
|
2
|
+
export { createProxyHandler, createAdminAuthRoute } from "./same-origin-proxy.js";
|
|
3
|
+
export { VENTURE_API_PREFIX, createVentureApiRoute } from "./venture_api_route.js";
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzL,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAClF,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { VENTURE_API_PREFIX, createVentureApiRoute
|
|
1
|
+
export { createProxyHandler, createAdminAuthRoute } from "./same-origin-proxy.js";
|
|
2
|
+
export { VENTURE_API_PREFIX, createVentureApiRoute } from "./venture_api_route.js";
|
|
3
3
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAClF,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -1,6 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* A non-empty list of exact hostnames this worker is permitted to serve.
|
|
3
|
+
* Encoded as a tuple with at least one element so the type system rejects
|
|
4
|
+
* an empty allowedHosts list at config time. Any inbound request whose
|
|
5
|
+
* `URL.hostname` does not match (case-insensitively) one of these entries
|
|
6
|
+
* is refused with a structured 404 before any route lookup runs.
|
|
7
|
+
*
|
|
8
|
+
* The match is exact — wildcards and suffix patterns are intentionally not
|
|
9
|
+
* supported. A worker that needs to serve `admin.example.com` AND
|
|
10
|
+
* `*.admin.example.com` must enumerate every concrete hostname it accepts.
|
|
11
|
+
* That keeps the binding contract auditable: every Cloudflare worker route
|
|
12
|
+
* has a corresponding entry here, and a misbinding becomes a 404 instead
|
|
13
|
+
* of a silent fall-through to the next handler.
|
|
14
|
+
*/
|
|
15
|
+
export type AllowedHosts = readonly [string, ...string[]];
|
|
2
16
|
interface BackendBase {
|
|
3
|
-
readonly
|
|
17
|
+
readonly baseUrl: string;
|
|
4
18
|
}
|
|
5
19
|
/**
|
|
6
20
|
* A backend identity. The `kind` discriminant determines the cookie-transform
|
|
@@ -55,7 +69,7 @@ export interface Route {
|
|
|
55
69
|
readonly rewrite: PathRewrite;
|
|
56
70
|
}
|
|
57
71
|
/**
|
|
58
|
-
* Result of probing a backend's `/
|
|
72
|
+
* Result of probing a backend's Jakuta `/status` endpoint.
|
|
59
73
|
*
|
|
60
74
|
* @field status - `"ok"` if the backend responded with a 2xx, `"error"` on non-2xx or network failure
|
|
61
75
|
* @field probeUrl - The full URL that was probed, useful for error reporting
|
|
@@ -89,10 +103,12 @@ export type ProxyHealthCheck = {
|
|
|
89
103
|
/**
|
|
90
104
|
* Declarative configuration for `createProxyHandler`.
|
|
91
105
|
*
|
|
106
|
+
* @field allowedHosts - Non-empty list of hostnames this worker is permitted to serve. Inbound requests for any other hostname are refused with a structured 404 before route dispatch. See {@link AllowedHosts}.
|
|
92
107
|
* @field routes - Ordered list of routes; first match wins
|
|
93
108
|
* @field healthCheck - Health-check hook configuration (use `{ kind: "disabled" }` to skip)
|
|
94
109
|
*/
|
|
95
110
|
export interface ProxyHandlerConfig {
|
|
111
|
+
readonly allowedHosts: AllowedHosts;
|
|
96
112
|
readonly routes: readonly Route[];
|
|
97
113
|
readonly healthCheck: ProxyHealthCheck;
|
|
98
114
|
}
|
|
@@ -139,22 +155,30 @@ export interface ProxyHandler {
|
|
|
139
155
|
* Spread the result into your `routes` array; do not hand-maintain the
|
|
140
156
|
* rewrite.
|
|
141
157
|
*
|
|
142
|
-
* @
|
|
143
|
-
* @
|
|
158
|
+
* @why Prevents each Worker from hand-writing the admin login rewrite because admin-shell's browser paths and admin-api's server paths intentionally differ.
|
|
159
|
+
* @param adminBaseUrl - Origin of the jakuta-admin API (scheme + host, no path)
|
|
160
|
+
* @returns A Route that matches `/auth` / `/auth/*` and forwards to `adminBaseUrl/api/auth/*`
|
|
144
161
|
*/
|
|
145
|
-
export declare function createAdminAuthRoute(
|
|
162
|
+
export declare function createAdminAuthRoute(adminBaseUrl: string): Route;
|
|
146
163
|
/**
|
|
147
164
|
* Build a `ProxyHandler` from a declarative `ProxyHandlerConfig`. This is the
|
|
148
165
|
* single handler constructor — there is no separate venture or central-admin
|
|
149
166
|
* handler. Consumers express their routing topology as a list of
|
|
150
167
|
* `Route`s pointing at `Backend`s, and the handler dispatches by first-match.
|
|
151
168
|
*
|
|
169
|
+
* Every config must declare its `allowedHosts` — the non-empty list of
|
|
170
|
+
* hostnames this worker accepts. A request for any other hostname is
|
|
171
|
+
* refused with a structured 404 before route dispatch, so a misbound
|
|
172
|
+
* Cloudflare worker route surfaces as a loud 404 instead of a silent
|
|
173
|
+
* fall-through to OpenNext/Next.js.
|
|
174
|
+
*
|
|
152
175
|
* The cookie transform applied on each hop is determined by the target
|
|
153
176
|
* backend's `kind` (`"admin"` → preserve cookie, `"venture"` → cookie-to-header
|
|
154
177
|
* handoff). There is no per-route override. See the `Backend` doc comment for
|
|
155
178
|
* why this is unrepresentable state, not a missing feature.
|
|
156
179
|
*
|
|
157
|
-
* @
|
|
180
|
+
* @why Centralizes host allowlisting, backend URL normalization, and cookie-transform routing because individual worker entries must not diverge on those security rules.
|
|
181
|
+
* @param config - Declarative host allowlist, route list, and health-check hook
|
|
158
182
|
* @returns A ProxyHandler whose `handleRequest` dispatches the inbound request
|
|
159
183
|
*/
|
|
160
184
|
export declare function createProxyHandler(config: ProxyHandlerConfig): ProxyHandler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"same-origin-proxy.d.ts","sourceRoot":"","sources":["../src/same-origin-proxy.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"same-origin-proxy.d.ts","sour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
3
|
+
if (originUrl.endsWith("/")) {
|
|
4
|
+
return originUrl.slice(0, -1);
|
|
5
|
+
}
|
|
6
|
+
return originUrl;
|
|
5
7
|
}
|
|
6
8
|
function jsonErrorResponse(errorInput) {
|
|
7
9
|
return new Response(JSON.stringify(errorInput.errorBody), {
|
|
@@ -9,13 +11,16 @@ function jsonErrorResponse(errorInput) {
|
|
|
9
11
|
headers: { "content-type": "application/json" },
|
|
10
12
|
});
|
|
11
13
|
}
|
|
12
|
-
async function probeHealth(
|
|
13
|
-
const probeUrl = new URL("/
|
|
14
|
+
async function probeHealth(probedBaseUrl) {
|
|
15
|
+
const probeUrl = new URL("/status", probedBaseUrl).toString();
|
|
14
16
|
try {
|
|
15
17
|
const healthResponse = await fetch(probeUrl, {
|
|
16
18
|
signal: AbortSignal.timeout(HEALTH_TIMEOUT_MS),
|
|
17
19
|
});
|
|
18
|
-
|
|
20
|
+
if (healthResponse.ok) {
|
|
21
|
+
return { status: "ok", probeUrl };
|
|
22
|
+
}
|
|
23
|
+
return { status: "error", probeUrl };
|
|
19
24
|
}
|
|
20
25
|
catch {
|
|
21
26
|
return { status: "error", probeUrl };
|
|
@@ -60,10 +65,19 @@ function stripInboundHandoffHeader(originalHeaders) {
|
|
|
60
65
|
}
|
|
61
66
|
async function forwardToBackend(forwardInput) {
|
|
62
67
|
const target = forwardInput.target;
|
|
63
|
-
const targetUrl = new URL(forwardInput.targetPath + forwardInput.originalUrl.search, target.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
:
|
|
68
|
+
const targetUrl = new URL(forwardInput.targetPath + forwardInput.originalUrl.search, target.baseUrl);
|
|
69
|
+
let forwardedHeaders;
|
|
70
|
+
switch (target.kind) {
|
|
71
|
+
case "venture":
|
|
72
|
+
forwardedHeaders = buildVentureForwardedHeaders(forwardInput.originalRequest.headers);
|
|
73
|
+
break;
|
|
74
|
+
case "admin":
|
|
75
|
+
forwardedHeaders = stripInboundHandoffHeader(forwardInput.originalRequest.headers);
|
|
76
|
+
break;
|
|
77
|
+
default:
|
|
78
|
+
forwardedHeaders = target;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
67
81
|
try {
|
|
68
82
|
return await fetch(new Request(targetUrl, {
|
|
69
83
|
method: forwardInput.originalRequest.method,
|
|
@@ -98,9 +112,6 @@ function matchPathPrefix(params) {
|
|
|
98
112
|
}
|
|
99
113
|
return { kind: "no_match" };
|
|
100
114
|
}
|
|
101
|
-
function assertNeverPathRewrite(rewrite) {
|
|
102
|
-
throw new Error(`unreachable PathRewrite variant: ${JSON.stringify(rewrite)}`);
|
|
103
|
-
}
|
|
104
115
|
function applyPathRewrite(params) {
|
|
105
116
|
switch (params.rewrite.kind) {
|
|
106
117
|
case "identity":
|
|
@@ -108,11 +119,32 @@ function applyPathRewrite(params) {
|
|
|
108
119
|
case "transform":
|
|
109
120
|
return params.rewrite.apply(params.incomingPath);
|
|
110
121
|
default:
|
|
111
|
-
return
|
|
122
|
+
return params.rewrite;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function matchAllowedHost(matchParams) {
|
|
126
|
+
const observedHostnameLower = matchParams.requestUrl.hostname.toLowerCase();
|
|
127
|
+
for (const allowedHost of matchParams.allowedHosts) {
|
|
128
|
+
if (observedHostnameLower === allowedHost.toLowerCase()) {
|
|
129
|
+
return { kind: "allowed" };
|
|
130
|
+
}
|
|
112
131
|
}
|
|
132
|
+
return { kind: "rejected", observedHostname: matchParams.requestUrl.hostname };
|
|
133
|
+
}
|
|
134
|
+
function buildHostRejectionResponse(rejectionInput) {
|
|
135
|
+
const configuredList = rejectionInput.allowedHosts.join(", ");
|
|
136
|
+
return jsonErrorResponse({
|
|
137
|
+
httpStatus: 404,
|
|
138
|
+
errorBody: {
|
|
139
|
+
error: "host_not_configured",
|
|
140
|
+
host: rejectionInput.observedHostname,
|
|
141
|
+
configured: configuredList,
|
|
142
|
+
message: `This worker received a request for Host '${rejectionInput.observedHostname}' but is only configured to serve: ${configuredList}. Check the Cloudflare worker route bindings — the binding for this hostname is pointing at the wrong worker.`,
|
|
143
|
+
},
|
|
144
|
+
});
|
|
113
145
|
}
|
|
114
146
|
function normalizeBackend(backend) {
|
|
115
|
-
return { kind: backend.kind,
|
|
147
|
+
return { kind: backend.kind, baseUrl: stripTrailingSlash(backend.baseUrl) };
|
|
116
148
|
}
|
|
117
149
|
function normalizeRoute(route) {
|
|
118
150
|
return {
|
|
@@ -121,9 +153,6 @@ function normalizeRoute(route) {
|
|
|
121
153
|
rewrite: route.rewrite,
|
|
122
154
|
};
|
|
123
155
|
}
|
|
124
|
-
function assertNeverHealthCheck(healthCheck) {
|
|
125
|
-
throw new Error(`unreachable ProxyHealthCheck variant: ${JSON.stringify(healthCheck)}`);
|
|
126
|
-
}
|
|
127
156
|
function normalizeHealthCheck(healthCheck) {
|
|
128
157
|
switch (healthCheck.kind) {
|
|
129
158
|
case "disabled":
|
|
@@ -136,7 +165,7 @@ function normalizeHealthCheck(healthCheck) {
|
|
|
136
165
|
buildHealthResponse: healthCheck.buildHealthResponse,
|
|
137
166
|
};
|
|
138
167
|
default:
|
|
139
|
-
return
|
|
168
|
+
return healthCheck;
|
|
140
169
|
}
|
|
141
170
|
}
|
|
142
171
|
/**
|
|
@@ -150,13 +179,14 @@ function normalizeHealthCheck(healthCheck) {
|
|
|
150
179
|
* Spread the result into your `routes` array; do not hand-maintain the
|
|
151
180
|
* rewrite.
|
|
152
181
|
*
|
|
153
|
-
* @
|
|
154
|
-
* @
|
|
182
|
+
* @why Prevents each Worker from hand-writing the admin login rewrite because admin-shell's browser paths and admin-api's server paths intentionally differ.
|
|
183
|
+
* @param adminBaseUrl - Origin of the jakuta-admin API (scheme + host, no path)
|
|
184
|
+
* @returns A Route that matches `/auth` / `/auth/*` and forwards to `adminBaseUrl/api/auth/*`
|
|
155
185
|
*/
|
|
156
|
-
export function createAdminAuthRoute(
|
|
186
|
+
export function createAdminAuthRoute(adminBaseUrl) {
|
|
157
187
|
return {
|
|
158
188
|
pathPrefix: "/auth",
|
|
159
|
-
target: { kind: "admin",
|
|
189
|
+
target: { kind: "admin", baseUrl: stripTrailingSlash(adminBaseUrl) },
|
|
160
190
|
rewrite: {
|
|
161
191
|
kind: "transform",
|
|
162
192
|
apply: (incomingPath) => "/api" + incomingPath,
|
|
@@ -169,30 +199,51 @@ export function createAdminAuthRoute(adminBase) {
|
|
|
169
199
|
* handler. Consumers express their routing topology as a list of
|
|
170
200
|
* `Route`s pointing at `Backend`s, and the handler dispatches by first-match.
|
|
171
201
|
*
|
|
202
|
+
* Every config must declare its `allowedHosts` — the non-empty list of
|
|
203
|
+
* hostnames this worker accepts. A request for any other hostname is
|
|
204
|
+
* refused with a structured 404 before route dispatch, so a misbound
|
|
205
|
+
* Cloudflare worker route surfaces as a loud 404 instead of a silent
|
|
206
|
+
* fall-through to OpenNext/Next.js.
|
|
207
|
+
*
|
|
172
208
|
* The cookie transform applied on each hop is determined by the target
|
|
173
209
|
* backend's `kind` (`"admin"` → preserve cookie, `"venture"` → cookie-to-header
|
|
174
210
|
* handoff). There is no per-route override. See the `Backend` doc comment for
|
|
175
211
|
* why this is unrepresentable state, not a missing feature.
|
|
176
212
|
*
|
|
177
|
-
* @
|
|
213
|
+
* @why Centralizes host allowlisting, backend URL normalization, and cookie-transform routing because individual worker entries must not diverge on those security rules.
|
|
214
|
+
* @param config - Declarative host allowlist, route list, and health-check hook
|
|
178
215
|
* @returns A ProxyHandler whose `handleRequest` dispatches the inbound request
|
|
179
216
|
*/
|
|
180
217
|
export function createProxyHandler(config) {
|
|
218
|
+
const normalizedAllowedHosts = config.allowedHosts;
|
|
181
219
|
const normalizedRoutes = config.routes.map(normalizeRoute);
|
|
182
220
|
const normalizedHealthCheck = normalizeHealthCheck(config.healthCheck);
|
|
183
221
|
return {
|
|
184
222
|
async handleRequest(workerRequest) {
|
|
185
223
|
const requestUrl = new URL(workerRequest.url);
|
|
224
|
+
const hostMatch = matchAllowedHost({
|
|
225
|
+
requestUrl,
|
|
226
|
+
allowedHosts: normalizedAllowedHosts,
|
|
227
|
+
});
|
|
228
|
+
if (hostMatch.kind === "rejected") {
|
|
229
|
+
return {
|
|
230
|
+
proxied: true,
|
|
231
|
+
proxiedResponse: buildHostRejectionResponse({
|
|
232
|
+
observedHostname: hostMatch.observedHostname,
|
|
233
|
+
allowedHosts: normalizedAllowedHosts,
|
|
234
|
+
}),
|
|
235
|
+
};
|
|
236
|
+
}
|
|
186
237
|
const pathname = requestUrl.pathname;
|
|
187
238
|
if (normalizedHealthCheck.kind === "enabled" &&
|
|
188
239
|
pathname === normalizedHealthCheck.path) {
|
|
189
240
|
const probeResults = await Promise.all(normalizedHealthCheck.probeTargets.map(async (backend) => {
|
|
190
|
-
const
|
|
191
|
-
return [backend.kind,
|
|
241
|
+
const probeResult = await probeHealth(backend.baseUrl);
|
|
242
|
+
return [backend.kind, probeResult];
|
|
192
243
|
}));
|
|
193
244
|
const resultsByKind = {};
|
|
194
|
-
for (const [kind,
|
|
195
|
-
resultsByKind[kind] =
|
|
245
|
+
for (const [kind, probeResult] of probeResults) {
|
|
246
|
+
resultsByKind[kind] = probeResult;
|
|
196
247
|
}
|
|
197
248
|
const proxiedResponse = normalizedHealthCheck.buildHealthResponse(resultsByKind);
|
|
198
249
|
return { proxied: true, proxiedResponse };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"same-origin-proxy.js","sourceRoot":"","sources":["../src/same-origin-proxy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"same-origin-proxy.js","sourceRoot":"","sources":["../src/same-origin-proxy.ts"],"names":[],"mappings":"AAuJA,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAE/B,SAAS,kBAAkB,CAAC,SAAiB;IAC3C,IAAI,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC5B,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,C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BACF,MAAM,aAAa,GAAsC,EAAE,CAAC;gBAC5D,KAAK,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,IAAI,YAAY,EAAE,CAAC;oBAC/C,aAAa,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC;gBACpC,CAAC;gBACD,MAAM,eAAe,GAAG,qBAAqB,CAAC,mBAAmB,CAAC,aAAa,CAAC,CAAC;gBACjF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC;YAC5C,CAAC;YAED,KAAK,MAAM,KAAK,IAAI,gBAAgB,EAAE,CAAC;gBACrC,MAAM,KAAK,GAAG,eAAe,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC;gBACtE,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;oBAC3B,MAAM,aAAa,GAAG,gBAAgB,CAAC;wBACrC,OAAO,EAAE,KAAK,CAAC,OAAO;wBACtB,YAAY,EAAE,QAAQ;qBACvB,CAAC,CAAC;oBACH,MAAM,eAAe,GAAG,MAAM,gBAAgB,CAAC;wBAC7C,eAAe,EAAE,aAAa;wBAC9B,WAAW,EAAE,UAAU;wBACvB,MAAM,EAAE,KAAK,CAAC,MAAM;wBACpB,UAAU,EAAE,aAAa;qBAC1B,CAAC,CAAC;oBACH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC;gBAC5C,CAAC;YACH,CAAC;YAED,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;QAC5B,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -6,8 +6,8 @@ export declare const VENTURE_API_PREFIX = "/api";
|
|
|
6
6
|
* Worker-side path contract aligned with the Rust `VENTURE_API_PREFIX`
|
|
7
7
|
* constant.
|
|
8
8
|
*
|
|
9
|
-
* @param
|
|
10
|
-
* @returns A Route that matches `/api` / `/api/*` and forwards to `
|
|
9
|
+
* @param ventureBaseUrl - Origin of the venture backend (scheme + host, no path).
|
|
10
|
+
* @returns A Route that matches `/api` / `/api/*` and forwards to `ventureBaseUrl`.
|
|
11
11
|
*/
|
|
12
|
-
export declare function createVentureApiRoute(
|
|
12
|
+
export declare function createVentureApiRoute(ventureBaseUrl: string): Route;
|
|
13
13
|
//# sourceMappingURL=venture_api_route.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"venture_api_route.d.ts","sourceRoot":"","sources":["../src/venture_api_route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAKpD,eAAO,MAAM,kBAAkB,SAAS,CAAC;AAEzC;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,
|
|
1
|
+
{"version":3,"file":"venture_api_route.d.ts","sourceRoot":"","sources":["../src/venture_api_route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAKpD,eAAO,MAAM,kBAAkB,SAAS,CAAC;AAEzC;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,cAAc,EAAE,MAAM,GAAG,KAAK,CAMnE"}
|
|
@@ -8,13 +8,13 @@ export const VENTURE_API_PREFIX = "/api";
|
|
|
8
8
|
* Worker-side path contract aligned with the Rust `VENTURE_API_PREFIX`
|
|
9
9
|
* constant.
|
|
10
10
|
*
|
|
11
|
-
* @param
|
|
12
|
-
* @returns A Route that matches `/api` / `/api/*` and forwards to `
|
|
11
|
+
* @param ventureBaseUrl - Origin of the venture backend (scheme + host, no path).
|
|
12
|
+
* @returns A Route that matches `/api` / `/api/*` and forwards to `ventureBaseUrl`.
|
|
13
13
|
*/
|
|
14
|
-
export function createVentureApiRoute(
|
|
14
|
+
export function createVentureApiRoute(ventureBaseUrl) {
|
|
15
15
|
return {
|
|
16
16
|
pathPrefix: VENTURE_API_PREFIX,
|
|
17
|
-
target: { kind: "venture",
|
|
17
|
+
target: { kind: "venture", baseUrl: ventureBaseUrl },
|
|
18
18
|
rewrite: { kind: "identity" },
|
|
19
19
|
};
|
|
20
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"venture_api_route.js","sourceRoot":"","sources":["../src/venture_api_route.ts"],"names":[],"mappings":"AAEA,yEAAyE;AACzE,2EAA2E;AAC3E,6EAA6E;AAC7E,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAEzC;;;;;;;;GAQG;AACH,MAAM,UAAU,qBAAqB,CAAC,
|
|
1
|
+
{"version":3,"file":"venture_api_route.js","sourceRoot":"","sources":["../src/venture_api_route.ts"],"names":[],"mappings":"AAEA,yEAAyE;AACzE,2EAA2E;AAC3E,6EAA6E;AAC7E,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAEzC;;;;;;;;GAQG;AACH,MAAM,UAAU,qBAAqB,CAAC,cAAsB;IACxD,OAAO;QACH,UAAU,EAAE,kBAAkB;QAC9B,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,cAAc,EAAE;QACpD,OAAO,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE;KAChC,CAAC;AACN,CAAC"}
|