@jakuta-inc/worker-proxy 0.1.3

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.
@@ -0,0 +1,3 @@
1
+ export type { WorkerProxyConfig, ProxyRequestParams, ProxyOutcome } from "./same-origin-proxy.js";
2
+ export { handleProxyRequest } from "./same-origin-proxy.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAClG,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { handleProxyRequest } from "./same-origin-proxy.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @field ventureApiBase - Origin of the venture's Fly.io backend (e.g. "https://venoble-backend.fly.dev")
3
+ * @field adminApiBase - Origin of the jakuta-admin API on Fly.io (e.g. "https://jakuta-admin-api.fly.dev")
4
+ */
5
+ export interface WorkerProxyConfig {
6
+ ventureApiBase: string;
7
+ adminApiBase: string;
8
+ }
9
+ /**
10
+ * @field request - The incoming Cloudflare Worker request to evaluate for proxy routing
11
+ * @field proxyConfig - Backend origins to proxy to
12
+ */
13
+ export interface ProxyRequestParams {
14
+ request: Request;
15
+ proxyConfig: WorkerProxyConfig;
16
+ }
17
+ /** Discriminated union: either the request was proxied or it should fall through to OpenNext. */
18
+ export type ProxyOutcome = {
19
+ readonly proxied: true;
20
+ readonly proxiedResponse: Response;
21
+ } | {
22
+ readonly proxied: false;
23
+ };
24
+ /**
25
+ * Evaluates an incoming request for proxy routing.
26
+ *
27
+ * /api/* requests proxy to the venture backend (path preserved).
28
+ * /auth/* requests proxy to the jakuta-admin API (rewritten to /api/auth/*).
29
+ * Everything else returns { proxied: false } so the caller can fall through
30
+ * to OpenNext for frontend rendering.
31
+ *
32
+ * @param proxyRequest - The request and proxy config
33
+ * @returns ProxyOutcome indicating whether the request was proxied
34
+ */
35
+ export declare function handleProxyRequest(proxyRequest: ProxyRequestParams): Promise<ProxyOutcome>;
36
+ //# sourceMappingURL=same-origin-proxy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"same-origin-proxy.d.ts","sourceRoot":"","sources":["../src/same-origin-proxy.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,iBAAiB,CAAC;CAChC;AAED,iGAAiG;AACjG,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;;;;;;;;;;GAUG;AACH,wBAAsB,kBAAkB,CACtC,YAAY,EAAE,kBAAkB,GAC/B,OAAO,CAAC,YAAY,CAAC,CAyBvB"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Evaluates an incoming request for proxy routing.
3
+ *
4
+ * /api/* requests proxy to the venture backend (path preserved).
5
+ * /auth/* requests proxy to the jakuta-admin API (rewritten to /api/auth/*).
6
+ * Everything else returns { proxied: false } so the caller can fall through
7
+ * to OpenNext for frontend rendering.
8
+ *
9
+ * @param proxyRequest - The request and proxy config
10
+ * @returns ProxyOutcome indicating whether the request was proxied
11
+ */
12
+ export async function handleProxyRequest(proxyRequest) {
13
+ const requestUrl = new URL(proxyRequest.request.url);
14
+ if (requestUrl.pathname.startsWith("/api/")) {
15
+ const proxiedResponse = await forwardToBackend({
16
+ originalRequest: proxyRequest.request,
17
+ originalUrl: requestUrl,
18
+ targetBase: proxyRequest.proxyConfig.ventureApiBase,
19
+ targetPath: requestUrl.pathname,
20
+ });
21
+ return { proxied: true, proxiedResponse };
22
+ }
23
+ if (requestUrl.pathname.startsWith("/auth/")) {
24
+ const adminPath = "/api" + requestUrl.pathname;
25
+ const proxiedResponse = await forwardToBackend({
26
+ originalRequest: proxyRequest.request,
27
+ originalUrl: requestUrl,
28
+ targetBase: proxyRequest.proxyConfig.adminApiBase,
29
+ targetPath: adminPath,
30
+ });
31
+ return { proxied: true, proxiedResponse };
32
+ }
33
+ return { proxied: false };
34
+ }
35
+ async function forwardToBackend(forwardParams) {
36
+ const targetUrl = new URL(forwardParams.targetPath + forwardParams.originalUrl.search, forwardParams.targetBase);
37
+ return fetch(new Request(targetUrl, {
38
+ method: forwardParams.originalRequest.method,
39
+ headers: forwardParams.originalRequest.headers,
40
+ body: forwardParams.originalRequest.body,
41
+ redirect: "manual",
42
+ }));
43
+ }
44
+ //# sourceMappingURL=same-origin-proxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"same-origin-proxy.js","sourceRoot":"","sources":["../src/same-origin-proxy.ts"],"names":[],"mappings":"AAuBA;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,YAAgC;IAEhC,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAErD,IAAI,UAAU,CAAC,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5C,MAAM,eAAe,GAAG,MAAM,gBAAgB,CAAC;YAC7C,eAAe,EAAE,YAAY,CAAC,OAAO;YACrC,WAAW,EAAE,UAAU;YACvB,UAAU,EAAE,YAAY,CAAC,WAAW,CAAC,cAAc;YACnD,UAAU,EAAE,UAAU,CAAC,QAAQ;SAChC,CAAC,CAAC;QACH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC;IAC5C,CAAC;IAED,IAAI,UAAU,CAAC,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC7C,MAAM,SAAS,GAAG,MAAM,GAAG,UAAU,CAAC,QAAQ,CAAC;QAC/C,MAAM,eAAe,GAAG,MAAM,gBAAgB,CAAC;YAC7C,eAAe,EAAE,YAAY,CAAC,OAAO;YACrC,WAAW,EAAE,UAAU;YACvB,UAAU,EAAE,YAAY,CAAC,WAAW,CAAC,YAAY;YACjD,UAAU,EAAE,SAAS;SACtB,CAAC,CAAC;QACH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC;IAC5C,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AAC5B,CAAC;AASD,KAAK,UAAU,gBAAgB,CAAC,aAA4B;IAC1D,MAAM,SAAS,GAAG,IAAI,GAAG,CACvB,aAAa,CAAC,UAAU,GAAG,aAAa,CAAC,WAAW,CAAC,MAAM,EAC3D,aAAa,CAAC,UAAU,CACzB,CAAC;IAEF,OAAO,KAAK,CACV,IAAI,OAAO,CAAC,SAAS,EAAE;QACrB,MAAM,EAAE,aAAa,CAAC,eAAe,CAAC,MAAM;QAC5C,OAAO,EAAE,aAAa,CAAC,eAAe,CAAC,OAAO;QAC9C,IAAI,EAAE,aAAa,CAAC,eAAe,CAAC,IAAI;QACxC,QAAQ,EAAE,QAAQ;KACnB,CAAC,CACH,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@jakuta-inc/worker-proxy",
3
+ "version": "0.1.3",
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
+ },
15
+ "publishConfig": {
16
+ "access": "restricted"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/Jakuta-Inc/jakuta-admin.git",
21
+ "directory": "packages/worker-proxy"
22
+ },
23
+ "devDependencies": {
24
+ "@cloudflare/workers-types": "^4.20250327.0",
25
+ "typescript": "^5.7.0"
26
+ }
27
+ }