@decocms/runtime 0.0.1-testing-beta.1 → 0.0.1-testing-beta.2
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,14 @@
|
|
|
1
|
+
import * as hono from 'hono';
|
|
2
|
+
import { Hono } from 'hono';
|
|
3
|
+
import * as hono_types from 'hono/types';
|
|
4
|
+
|
|
5
|
+
interface AssetServerConfig {
|
|
6
|
+
env: "development" | "production" | "test";
|
|
7
|
+
localDevProxyUrl?: string | URL;
|
|
8
|
+
assetsDirectory?: string;
|
|
9
|
+
}
|
|
10
|
+
declare const applyAssetServerRoutes: (app: Hono, config: AssetServerConfig) => void;
|
|
11
|
+
declare const createAssetServer: (config: AssetServerConfig) => Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">;
|
|
12
|
+
declare const createAssetServerFetcher: (config: AssetServerConfig) => (request: Request, Env?: unknown, executionCtx?: hono.ExecutionContext) => Response | Promise<Response>;
|
|
13
|
+
|
|
14
|
+
export { applyAssetServerRoutes, createAssetServer, createAssetServerFetcher };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { serveStatic } from 'hono/bun';
|
|
2
|
+
import { Hono } from 'hono';
|
|
3
|
+
import { proxy } from 'hono/proxy';
|
|
4
|
+
|
|
5
|
+
// src/bun-asset-server/index.ts
|
|
6
|
+
var devServerProxy = (url) => (c) => {
|
|
7
|
+
const incomingUrl = new URL(c.req.raw.url);
|
|
8
|
+
const target = new URL(url);
|
|
9
|
+
target.pathname = incomingUrl.pathname;
|
|
10
|
+
target.search = incomingUrl.search;
|
|
11
|
+
return proxy(target, {
|
|
12
|
+
raw: c.req.raw,
|
|
13
|
+
headers: {
|
|
14
|
+
...c.req.raw.headers
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// src/bun-asset-server/index.ts
|
|
20
|
+
var DEFAULT_LOCAL_DEV_PROXY_URL = "http://localhost:4000";
|
|
21
|
+
var DEFAULT_ASSETS_DIRECTORY = "./dist";
|
|
22
|
+
var applyAssetServerRoutes = (app, config) => {
|
|
23
|
+
const environment = config.env;
|
|
24
|
+
const localDevProxyUrl = config.localDevProxyUrl ?? DEFAULT_LOCAL_DEV_PROXY_URL;
|
|
25
|
+
const assetsDirectory = config.assetsDirectory ?? DEFAULT_ASSETS_DIRECTORY;
|
|
26
|
+
if (environment === "development") {
|
|
27
|
+
app.use("*", devServerProxy(localDevProxyUrl));
|
|
28
|
+
} else if (environment === "production") {
|
|
29
|
+
app.use("/assets/*", serveStatic({ root: assetsDirectory }));
|
|
30
|
+
app.get("*", serveStatic({ path: `${assetsDirectory}/index.html` }));
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var createAssetServer = (config) => {
|
|
34
|
+
const app = new Hono();
|
|
35
|
+
applyAssetServerRoutes(app, config);
|
|
36
|
+
return app;
|
|
37
|
+
};
|
|
38
|
+
var createAssetServerFetcher = (config) => {
|
|
39
|
+
const app = new Hono();
|
|
40
|
+
applyAssetServerRoutes(app, config);
|
|
41
|
+
return app.fetch;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export { applyAssetServerRoutes, createAssetServer, createAssetServerFetcher };
|
|
45
|
+
//# sourceMappingURL=bun-asset-server.js.map
|
|
46
|
+
//# sourceMappingURL=bun-asset-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/bun-asset-server/dev-server-proxy.ts","../src/bun-asset-server/index.ts"],"names":[],"mappings":";;;;;AAGO,IAAM,cAAA,GAAiB,CAAC,GAAA,KAAsB,CAAC,CAAA,KAAe;AACnE,EAAA,MAAM,cAAc,IAAI,GAAA,CAAI,CAAA,CAAE,GAAA,CAAI,IAAI,GAAG,CAAA;AACzC,EAAA,MAAM,MAAA,GAAS,IAAI,GAAA,CAAI,GAAG,CAAA;AAC1B,EAAA,MAAA,CAAO,WAAW,WAAA,CAAY,QAAA;AAC9B,EAA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AAA;AAClC,EAAA,OAAO,GAAA,CAAI,KAAA;AACb","file":"bun-asset-server.js","sourcesContent":["import { proxy } from \"hono/proxy\";\nimport { Context } from \"hono\";\n\nexport const devServerProxy = (url: string | URL) => (c: Context) => {\n const incomingUrl = new URL(c.req.raw.url);\n const target = new URL(url);\n target.pathname = incomingUrl.pathname;\n target.search = incomingUrl.search;\n\n return proxy(target, {\n raw: c.req.raw,\n headers: {\n ...c.req.raw.headers,\n },\n });\n};\n","import { serveStatic } from \"hono/bun\";\nimport { Hono } from \"hono\";\nimport { devServerProxy } from \"./dev-server-proxy\";\n\ninterface AssetServerConfig {\n env: \"development\" | \"production\" | \"test\";\n localDevProxyUrl?: string | URL;\n assetsDirectory?: string;\n}\n\nconst DEFAULT_LOCAL_DEV_PROXY_URL = \"http://localhost:4000\";\nconst DEFAULT_ASSETS_DIRECTORY = \"./dist\";\n\nexport const applyAssetServerRoutes = (app: Hono, config: AssetServerConfig) => {\n const environment = config.env;\n const localDevProxyUrl = config.localDevProxyUrl ?? DEFAULT_LOCAL_DEV_PROXY_URL;\n const assetsDirectory = config.assetsDirectory ?? DEFAULT_ASSETS_DIRECTORY;\n\n if (environment === \"development\") {\n app.use(\"*\", devServerProxy(localDevProxyUrl));\n } else if (environment === \"production\") {\n app.use(\"/assets/*\", serveStatic({ root: assetsDirectory }));\n app.get(\"*\", serveStatic({ path: `${assetsDirectory}/index.html` }));\n }\n}\n\nexport const createAssetServer = (config: AssetServerConfig) => {\n const app = new Hono();\n applyAssetServerRoutes(app, config);\n return app;\n}\n\nexport const createAssetServerFetcher = (config: AssetServerConfig) => {\n const app = new Hono();\n applyAssetServerRoutes(app, config);\n return app.fetch;\n}"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/runtime",
|
|
3
|
-
"version": "0.0.1-testing-beta.
|
|
3
|
+
"version": "0.0.1-testing-beta.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsup",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"@modelcontextprotocol/sdk": "^1.19.1",
|
|
14
14
|
"bidc": "0.0.3",
|
|
15
15
|
"drizzle-orm": "^0.44.5",
|
|
16
|
+
"hono": "^4.10.7",
|
|
16
17
|
"jose": "^6.0.11",
|
|
17
18
|
"mime-db": "1.52.0",
|
|
18
19
|
"zod": "^3.25.76",
|
|
@@ -81,6 +82,11 @@
|
|
|
81
82
|
"source": "./src/bindings/deconfig/index.ts",
|
|
82
83
|
"types": "./dist/bindings/deconfig/index.d.ts",
|
|
83
84
|
"default": "./dist/bindings/deconfig/index.js"
|
|
85
|
+
},
|
|
86
|
+
"./bun-asset-server": {
|
|
87
|
+
"source": "./src/bun-asset-server/index.ts",
|
|
88
|
+
"types": "./dist/bun-asset-server/index.d.ts",
|
|
89
|
+
"default": "./dist/bun-asset-server/index.js"
|
|
84
90
|
}
|
|
85
91
|
},
|
|
86
92
|
"devDependencies": {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { proxy } from "hono/proxy";
|
|
2
|
+
import { Context } from "hono";
|
|
3
|
+
|
|
4
|
+
export const devServerProxy = (url: string | URL) => (c: Context) => {
|
|
5
|
+
const incomingUrl = new URL(c.req.raw.url);
|
|
6
|
+
const target = new URL(url);
|
|
7
|
+
target.pathname = incomingUrl.pathname;
|
|
8
|
+
target.search = incomingUrl.search;
|
|
9
|
+
|
|
10
|
+
return proxy(target, {
|
|
11
|
+
raw: c.req.raw,
|
|
12
|
+
headers: {
|
|
13
|
+
...c.req.raw.headers,
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { serveStatic } from "hono/bun";
|
|
2
|
+
import { Hono } from "hono";
|
|
3
|
+
import { devServerProxy } from "./dev-server-proxy";
|
|
4
|
+
|
|
5
|
+
interface AssetServerConfig {
|
|
6
|
+
env: "development" | "production" | "test";
|
|
7
|
+
localDevProxyUrl?: string | URL;
|
|
8
|
+
assetsDirectory?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const DEFAULT_LOCAL_DEV_PROXY_URL = "http://localhost:4000";
|
|
12
|
+
const DEFAULT_ASSETS_DIRECTORY = "./dist";
|
|
13
|
+
|
|
14
|
+
export const applyAssetServerRoutes = (app: Hono, config: AssetServerConfig) => {
|
|
15
|
+
const environment = config.env;
|
|
16
|
+
const localDevProxyUrl = config.localDevProxyUrl ?? DEFAULT_LOCAL_DEV_PROXY_URL;
|
|
17
|
+
const assetsDirectory = config.assetsDirectory ?? DEFAULT_ASSETS_DIRECTORY;
|
|
18
|
+
|
|
19
|
+
if (environment === "development") {
|
|
20
|
+
app.use("*", devServerProxy(localDevProxyUrl));
|
|
21
|
+
} else if (environment === "production") {
|
|
22
|
+
app.use("/assets/*", serveStatic({ root: assetsDirectory }));
|
|
23
|
+
app.get("*", serveStatic({ path: `${assetsDirectory}/index.html` }));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const createAssetServer = (config: AssetServerConfig) => {
|
|
28
|
+
const app = new Hono();
|
|
29
|
+
applyAssetServerRoutes(app, config);
|
|
30
|
+
return app;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const createAssetServerFetcher = (config: AssetServerConfig) => {
|
|
34
|
+
const app = new Hono();
|
|
35
|
+
applyAssetServerRoutes(app, config);
|
|
36
|
+
return app.fetch;
|
|
37
|
+
}
|