@jakuta-inc/worker-proxy 5.0.0 → 6.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 +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/same-origin-proxy.d.ts +30 -6
- package/dist/same-origin-proxy.d.ts.map +1 -1
- package/dist/same-origin-proxy.js +56 -14
- package/dist/same-origin-proxy.js.map +1 -1
- package/dist/venture_api_route.d.ts +13 -0
- package/dist/venture_api_route.d.ts.map +1 -0
- package/dist/venture_api_route.js +21 -0
- package/dist/venture_api_route.js.map +1 -0
- package/package.json +28 -28
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export type { Backend, PathRewrite, Route, HealthProbeResult, ProxyHealthCheck, ProxyHandlerConfig, ProxyOutcome, ProxyHandler, ProxyError
|
|
2
|
-
export {
|
|
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";
|
|
3
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,2 +1,3 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createProxyHandler, createAdminAuthRoute } from "./same-origin-proxy.js";
|
|
2
|
+
export { VENTURE_API_PREFIX, createVentureApiRoute } from "./venture_api_route.js";
|
|
2
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
|
|
@@ -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 Bridges the browser-facing /auth/* path family that admin-shell expects to the admin API's /api/auth/* surface, so every Worker proxy that mounts admin login uses the identical rewrite.
|
|
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 Single constructor for every Worker proxy in the admin family — the only place that reads {@link AllowedHosts}, normalizes backend URLs, and wires the cookie-transform / route-dispatch invariants together so individual workers cannot accidentally diverge.
|
|
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","sourceRoot":"","sources":["../src/same-origin-proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,YAAY,GAAG,SAAS,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;AAE1D,UAAU,WAAW;IACnB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,OAAO,GACf,CAAC,WAAW,GAAG;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Q,CAAC,WAAW,EAAE,gBAAgB,CAAC;CACxC;AAED;;;;;GAKG;AACH,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;;;;;;GAMG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,qBAAqB,CAAC;IACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;CACvC;AAED;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,aAAa,CAAC,aAAa,EAAE,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CAC9D;AA4OD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,MAAM,GAAG,KAAK,CAShE;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,GAAG,YAAY,CA+D3E"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export const ADMIN_API_BASE = "https://jakuta-admin-api.fly.dev";
|
|
2
1
|
const HEALTH_TIMEOUT_MS = 5000;
|
|
3
2
|
function stripTrailingSlash(originUrl) {
|
|
4
3
|
return originUrl.endsWith("/") ? originUrl.slice(0, -1) : originUrl;
|
|
@@ -9,8 +8,8 @@ function jsonErrorResponse(errorInput) {
|
|
|
9
8
|
headers: { "content-type": "application/json" },
|
|
10
9
|
});
|
|
11
10
|
}
|
|
12
|
-
async function probeHealth(
|
|
13
|
-
const probeUrl = new URL("/health",
|
|
11
|
+
async function probeHealth(probedBaseUrl) {
|
|
12
|
+
const probeUrl = new URL("/health", probedBaseUrl).toString();
|
|
14
13
|
try {
|
|
15
14
|
const healthResponse = await fetch(probeUrl, {
|
|
16
15
|
signal: AbortSignal.timeout(HEALTH_TIMEOUT_MS),
|
|
@@ -60,7 +59,7 @@ function stripInboundHandoffHeader(originalHeaders) {
|
|
|
60
59
|
}
|
|
61
60
|
async function forwardToBackend(forwardInput) {
|
|
62
61
|
const target = forwardInput.target;
|
|
63
|
-
const targetUrl = new URL(forwardInput.targetPath + forwardInput.originalUrl.search, target.
|
|
62
|
+
const targetUrl = new URL(forwardInput.targetPath + forwardInput.originalUrl.search, target.baseUrl);
|
|
64
63
|
const forwardedHeaders = target.kind === "venture"
|
|
65
64
|
? buildVentureForwardedHeaders(forwardInput.originalRequest.headers)
|
|
66
65
|
: stripInboundHandoffHeader(forwardInput.originalRequest.headers);
|
|
@@ -111,8 +110,29 @@ function applyPathRewrite(params) {
|
|
|
111
110
|
return assertNeverPathRewrite(params.rewrite);
|
|
112
111
|
}
|
|
113
112
|
}
|
|
113
|
+
function matchAllowedHost(matchParams) {
|
|
114
|
+
const observedHostnameLower = matchParams.requestUrl.hostname.toLowerCase();
|
|
115
|
+
for (const allowedHost of matchParams.allowedHosts) {
|
|
116
|
+
if (observedHostnameLower === allowedHost.toLowerCase()) {
|
|
117
|
+
return { kind: "allowed" };
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return { kind: "rejected", observedHostname: matchParams.requestUrl.hostname };
|
|
121
|
+
}
|
|
122
|
+
function buildHostRejectionResponse(rejectionInput) {
|
|
123
|
+
const configuredList = rejectionInput.allowedHosts.join(", ");
|
|
124
|
+
return jsonErrorResponse({
|
|
125
|
+
httpStatus: 404,
|
|
126
|
+
errorBody: {
|
|
127
|
+
error: "host_not_configured",
|
|
128
|
+
host: rejectionInput.observedHostname,
|
|
129
|
+
configured: configuredList,
|
|
130
|
+
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.`,
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
}
|
|
114
134
|
function normalizeBackend(backend) {
|
|
115
|
-
return { kind: backend.kind,
|
|
135
|
+
return { kind: backend.kind, baseUrl: stripTrailingSlash(backend.baseUrl) };
|
|
116
136
|
}
|
|
117
137
|
function normalizeRoute(route) {
|
|
118
138
|
return {
|
|
@@ -150,13 +170,14 @@ function normalizeHealthCheck(healthCheck) {
|
|
|
150
170
|
* Spread the result into your `routes` array; do not hand-maintain the
|
|
151
171
|
* rewrite.
|
|
152
172
|
*
|
|
153
|
-
* @
|
|
154
|
-
* @
|
|
173
|
+
* @why Bridges the browser-facing /auth/* path family that admin-shell expects to the admin API's /api/auth/* surface, so every Worker proxy that mounts admin login uses the identical rewrite.
|
|
174
|
+
* @param adminBaseUrl - Origin of the jakuta-admin API (scheme + host, no path)
|
|
175
|
+
* @returns A Route that matches `/auth` / `/auth/*` and forwards to `adminBaseUrl/api/auth/*`
|
|
155
176
|
*/
|
|
156
|
-
export function createAdminAuthRoute(
|
|
177
|
+
export function createAdminAuthRoute(adminBaseUrl) {
|
|
157
178
|
return {
|
|
158
179
|
pathPrefix: "/auth",
|
|
159
|
-
target: { kind: "admin",
|
|
180
|
+
target: { kind: "admin", baseUrl: stripTrailingSlash(adminBaseUrl) },
|
|
160
181
|
rewrite: {
|
|
161
182
|
kind: "transform",
|
|
162
183
|
apply: (incomingPath) => "/api" + incomingPath,
|
|
@@ -169,30 +190,51 @@ export function createAdminAuthRoute(adminBase) {
|
|
|
169
190
|
* handler. Consumers express their routing topology as a list of
|
|
170
191
|
* `Route`s pointing at `Backend`s, and the handler dispatches by first-match.
|
|
171
192
|
*
|
|
193
|
+
* Every config must declare its `allowedHosts` — the non-empty list of
|
|
194
|
+
* hostnames this worker accepts. A request for any other hostname is
|
|
195
|
+
* refused with a structured 404 before route dispatch, so a misbound
|
|
196
|
+
* Cloudflare worker route surfaces as a loud 404 instead of a silent
|
|
197
|
+
* fall-through to OpenNext/Next.js.
|
|
198
|
+
*
|
|
172
199
|
* The cookie transform applied on each hop is determined by the target
|
|
173
200
|
* backend's `kind` (`"admin"` → preserve cookie, `"venture"` → cookie-to-header
|
|
174
201
|
* handoff). There is no per-route override. See the `Backend` doc comment for
|
|
175
202
|
* why this is unrepresentable state, not a missing feature.
|
|
176
203
|
*
|
|
177
|
-
* @
|
|
204
|
+
* @why Single constructor for every Worker proxy in the admin family — the only place that reads {@link AllowedHosts}, normalizes backend URLs, and wires the cookie-transform / route-dispatch invariants together so individual workers cannot accidentally diverge.
|
|
205
|
+
* @param config - Declarative host allowlist, route list, and health-check hook
|
|
178
206
|
* @returns A ProxyHandler whose `handleRequest` dispatches the inbound request
|
|
179
207
|
*/
|
|
180
208
|
export function createProxyHandler(config) {
|
|
209
|
+
const normalizedAllowedHosts = config.allowedHosts;
|
|
181
210
|
const normalizedRoutes = config.routes.map(normalizeRoute);
|
|
182
211
|
const normalizedHealthCheck = normalizeHealthCheck(config.healthCheck);
|
|
183
212
|
return {
|
|
184
213
|
async handleRequest(workerRequest) {
|
|
185
214
|
const requestUrl = new URL(workerRequest.url);
|
|
215
|
+
const hostMatch = matchAllowedHost({
|
|
216
|
+
requestUrl,
|
|
217
|
+
allowedHosts: normalizedAllowedHosts,
|
|
218
|
+
});
|
|
219
|
+
if (hostMatch.kind === "rejected") {
|
|
220
|
+
return {
|
|
221
|
+
proxied: true,
|
|
222
|
+
proxiedResponse: buildHostRejectionResponse({
|
|
223
|
+
observedHostname: hostMatch.observedHostname,
|
|
224
|
+
allowedHosts: normalizedAllowedHosts,
|
|
225
|
+
}),
|
|
226
|
+
};
|
|
227
|
+
}
|
|
186
228
|
const pathname = requestUrl.pathname;
|
|
187
229
|
if (normalizedHealthCheck.kind === "enabled" &&
|
|
188
230
|
pathname === normalizedHealthCheck.path) {
|
|
189
231
|
const probeResults = await Promise.all(normalizedHealthCheck.probeTargets.map(async (backend) => {
|
|
190
|
-
const
|
|
191
|
-
return [backend.kind,
|
|
232
|
+
const probeResult = await probeHealth(backend.baseUrl);
|
|
233
|
+
return [backend.kind, probeResult];
|
|
192
234
|
}));
|
|
193
235
|
const resultsByKind = {};
|
|
194
|
-
for (const [kind,
|
|
195
|
-
resultsByKind[kind] =
|
|
236
|
+
for (const [kind, probeResult] of probeResults) {
|
|
237
|
+
resultsByKind[kind] = probeResult;
|
|
196
238
|
}
|
|
197
239
|
const proxiedResponse = normalizedHealthCheck.buildHealthResponse(resultsByKind);
|
|
198
240
|
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,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,aAAqB;IAC9C,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC9D,IAAI,CAAC;QACH,MAAM,cAAc,GAAG,MAAM,KAAK,CAAC,QAAQ,EAAE;YAC3C,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,iBAAiB,CAAC;SAC/C,CAA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G,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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Route } from "./same-origin-proxy.js";
|
|
2
|
+
export declare const VENTURE_API_PREFIX = "/api";
|
|
3
|
+
/**
|
|
4
|
+
* @why Builds the canonical venture-api route from a venture origin so
|
|
5
|
+
* every venture Worker proxy mounts `/api/*` the same way, keeping the
|
|
6
|
+
* Worker-side path contract aligned with the Rust `VENTURE_API_PREFIX`
|
|
7
|
+
* constant.
|
|
8
|
+
*
|
|
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
|
+
*/
|
|
12
|
+
export declare function createVentureApiRoute(ventureBaseUrl: string): Route;
|
|
13
|
+
//# sourceMappingURL=venture_api_route.d.ts.map
|
|
@@ -0,0 +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,cAAc,EAAE,MAAM,GAAG,KAAK,CAMnE"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Mirror of `crates/jakuta-cli-core/src/venture_api_prefix.rs` — the two
|
|
2
|
+
// constants MUST stay byte-identical so venture backends, venture plugins,
|
|
3
|
+
// and venture Worker proxies all agree on where the admin surface is nested.
|
|
4
|
+
export const VENTURE_API_PREFIX = "/api";
|
|
5
|
+
/**
|
|
6
|
+
* @why Builds the canonical venture-api route from a venture origin so
|
|
7
|
+
* every venture Worker proxy mounts `/api/*` the same way, keeping the
|
|
8
|
+
* Worker-side path contract aligned with the Rust `VENTURE_API_PREFIX`
|
|
9
|
+
* constant.
|
|
10
|
+
*
|
|
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
|
+
*/
|
|
14
|
+
export function createVentureApiRoute(ventureBaseUrl) {
|
|
15
|
+
return {
|
|
16
|
+
pathPrefix: VENTURE_API_PREFIX,
|
|
17
|
+
target: { kind: "venture", baseUrl: ventureBaseUrl },
|
|
18
|
+
rewrite: { kind: "identity" },
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=venture_api_route.js.map
|
|
@@ -0,0 +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,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"}
|
package/package.json
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@jakuta-inc/worker-proxy",
|
|
3
|
-
"version": "
|
|
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": "6.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
|
+
}
|