devframe 0.6.0 → 0.6.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.
@@ -1,6 +1,6 @@
1
1
  import { n as colors } from "../diagnostics-reporter-CsIG85Q5.mjs";
2
2
  import { createBuild } from "./build.mjs";
3
- import { n as resolveDevServerPort, t as createDevServer } from "../dev-zC5542OV.mjs";
3
+ import { n as resolveDevServerPort, t as createDevServer } from "../dev-DE51PeJc.mjs";
4
4
  import process from "node:process";
5
5
  import cac from "cac";
6
6
  import { safeParse } from "valibot";
@@ -1,2 +1,2 @@
1
- import { n as resolveDevServerPort, t as createDevServer } from "../dev-zC5542OV.mjs";
1
+ import { n as resolveDevServerPort, t as createDevServer } from "../dev-DE51PeJc.mjs";
2
2
  export { createDevServer, resolveDevServerPort };
@@ -1,7 +1,7 @@
1
1
  import { DEVFRAME_CONNECTION_META_FILENAME } from "./constants.mjs";
2
2
  import { a as diagnostics } from "./storage-yrUZaiib.mjs";
3
3
  import { n as createHostContext, t as createH3DevframeHost } from "./host-h3-Dsf-Tgwx.mjs";
4
- import { t as startHttpAndWs } from "./server-CAsvfJNK.mjs";
4
+ import { i as normalizeHttpServerUrl, t as startHttpAndWs } from "./server-CRFYfRqK.mjs";
5
5
  import { n as resolveBasePath, t as normalizeBasePath } from "./_shared-bWRzeSa0.mjs";
6
6
  import { t as open } from "./open-Deb5xmIT.mjs";
7
7
  import { mountStaticHandler } from "./utils/serve-static.mjs";
@@ -272,7 +272,7 @@ async function createDevServer(def, options = {}) {
272
272
  const basePath = options.basePath ? normalizeBasePath(options.basePath) : resolveBasePath(def, "standalone");
273
273
  const app = options.app ?? new H3();
274
274
  const h3Host = createH3DevframeHost({
275
- origin: `http://${host}:${port}`,
275
+ origin: normalizeHttpServerUrl(host, port),
276
276
  appName: def.id,
277
277
  mount: (base, dir) => {
278
278
  mountStaticHandler(app, base, dir);
@@ -2,7 +2,7 @@ import { DEVFRAME_CONNECTION_META_FILENAME, DEVFRAME_WS_ROUTE } from "../constan
2
2
  import { a as diagnostics } from "../storage-yrUZaiib.mjs";
3
3
  import { n as resolveBasePath, t as normalizeBasePath } from "../_shared-bWRzeSa0.mjs";
4
4
  import { serveStaticNodeMiddleware } from "../utils/serve-static.mjs";
5
- import { n as resolveDevServerPort, t as createDevServer } from "../dev-zC5542OV.mjs";
5
+ import { n as resolveDevServerPort, t as createDevServer } from "../dev-DE51PeJc.mjs";
6
6
  import { resolve } from "pathe";
7
7
  //#region src/helpers/vite.ts
8
8
  /**
@@ -183,6 +183,10 @@ declare function createStorage<T extends object>(options: CreateStorageOptions<T
183
183
  //#endregion
184
184
  //#region src/node/utils.d.ts
185
185
  declare function isObject(value: unknown): value is Record<string, any>;
186
+ /** Map a bind host to a host a client can actually connect to. */
187
+ declare function toDialableHost(host: string): string;
188
+ /** Format a bind host for use in a URL authority (dialable, IPv6-bracketed). */
189
+ declare function formatHostForUrl(host: string): string;
186
190
  declare function normalizeHttpServerUrl(host: string, port: number | string): string;
187
191
  //#endregion
188
- export { CreateH3DevframeHostOptions, CreateHostContextOptions, CreateStorageOptions, DevframeAgentHost, DevframeDiagnosticsHost, DevframeViewHost, RpcFunctionsHost, StartHttpAndWsOptions, StartedServer, createH3DevframeHost, createHostContext, createNodeSettings, createRpcSharedStateServerHost, createRpcStreamingServerHost, createScopedNodeContext, createStorage, isObject, normalizeHttpServerUrl, startHttpAndWs };
192
+ export { CreateH3DevframeHostOptions, CreateHostContextOptions, CreateStorageOptions, DevframeAgentHost, DevframeDiagnosticsHost, DevframeViewHost, RpcFunctionsHost, StartHttpAndWsOptions, StartedServer, createH3DevframeHost, createHostContext, createNodeSettings, createRpcSharedStateServerHost, createRpcStreamingServerHost, createScopedNodeContext, createStorage, formatHostForUrl, isObject, normalizeHttpServerUrl, startHttpAndWs, toDialableHost };
@@ -1,13 +1,4 @@
1
1
  import { t as createStorage } from "../storage-yrUZaiib.mjs";
2
2
  import { a as DevframeViewHost, c as createRpcSharedStateServerHost, i as createNodeSettings, l as DevframeDiagnosticsHost, n as createHostContext, o as RpcFunctionsHost, r as createScopedNodeContext, s as createRpcStreamingServerHost, t as createH3DevframeHost, u as DevframeAgentHost } from "../host-h3-Dsf-Tgwx.mjs";
3
- import { t as startHttpAndWs } from "../server-CAsvfJNK.mjs";
4
- import { isIP } from "node:net";
5
- //#region src/node/utils.ts
6
- function isObject(value) {
7
- return Object.prototype.toString.call(value) === "[object Object]";
8
- }
9
- function normalizeHttpServerUrl(host, port) {
10
- return `http://${host === "127.0.0.1" ? "localhost" : isIP(host) === 6 ? `[${host}]` : host}:${port}`;
11
- }
12
- //#endregion
13
- export { DevframeAgentHost, DevframeDiagnosticsHost, DevframeViewHost, RpcFunctionsHost, createH3DevframeHost, createHostContext, createNodeSettings, createRpcSharedStateServerHost, createRpcStreamingServerHost, createScopedNodeContext, createStorage, isObject, normalizeHttpServerUrl, startHttpAndWs };
3
+ import { a as toDialableHost, i as normalizeHttpServerUrl, n as formatHostForUrl, r as isObject, t as startHttpAndWs } from "../server-CRFYfRqK.mjs";
4
+ export { DevframeAgentHost, DevframeDiagnosticsHost, DevframeViewHost, RpcFunctionsHost, createH3DevframeHost, createHostContext, createNodeSettings, createRpcSharedStateServerHost, createRpcStreamingServerHost, createScopedNodeContext, createStorage, formatHostForUrl, isObject, normalizeHttpServerUrl, startHttpAndWs, toDialableHost };
@@ -5,6 +5,31 @@ import { t as getInternalContext } from "./context-CKJheEtf.mjs";
5
5
  import { createServer } from "node:http";
6
6
  import { AsyncLocalStorage } from "node:async_hooks";
7
7
  import { H3, toNodeHandler } from "h3";
8
+ import { isIP } from "node:net";
9
+ //#region src/node/utils.ts
10
+ function isObject(value) {
11
+ return Object.prototype.toString.call(value) === "[object Object]";
12
+ }
13
+ const NON_DIALABLE_HOSTS = /* @__PURE__ */ new Set([
14
+ "0.0.0.0",
15
+ "127.0.0.1",
16
+ "::",
17
+ "0000:0000:0000:0000:0000:0000:0000:0000",
18
+ ""
19
+ ]);
20
+ /** Map a bind host to a host a client can actually connect to. */
21
+ function toDialableHost(host) {
22
+ return NON_DIALABLE_HOSTS.has(host) ? "localhost" : host;
23
+ }
24
+ /** Format a bind host for use in a URL authority (dialable, IPv6-bracketed). */
25
+ function formatHostForUrl(host) {
26
+ const dialable = toDialableHost(host);
27
+ return isIP(dialable) === 6 ? `[${dialable}]` : dialable;
28
+ }
29
+ function normalizeHttpServerUrl(host, port) {
30
+ return `http://${formatHostForUrl(host)}:${port}`;
31
+ }
32
+ //#endregion
8
33
  //#region src/node/server.ts
9
34
  /**
10
35
  * Compose an h3 + WebSocket server for a devframe context. The RPC
@@ -83,9 +108,10 @@ async function startHttpAndWs(options) {
83
108
  });
84
109
  const address = httpServer.address();
85
110
  const resolvedPort = typeof address === "object" && address ? address.port : port;
86
- const origin = `http://${bindHost}:${resolvedPort}`;
111
+ const origin = normalizeHttpServerUrl(bindHost, resolvedPort);
87
112
  const internal = getInternalContext(context);
88
- const wsUrl = `ws://${bindHost}:${separateWsPort ?? resolvedPort}${options.path ?? ""}`;
113
+ const wsPortForUrl = separateWsPort ?? resolvedPort;
114
+ const wsUrl = `ws://${formatHostForUrl(bindHost)}:${wsPortForUrl}${options.path ?? ""}`;
89
115
  internal.wsEndpoint = { url: wsUrl };
90
116
  if (options.onReady) await options.onReady({
91
117
  origin,
@@ -119,4 +145,4 @@ async function startHttpAndWs(options) {
119
145
  };
120
146
  }
121
147
  //#endregion
122
- export { startHttpAndWs as t };
148
+ export { toDialableHost as a, normalizeHttpServerUrl as i, formatHostForUrl as n, isObject as r, startHttpAndWs as t };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "devframe",
3
3
  "type": "module",
4
- "version": "0.6.0",
4
+ "version": "0.6.1",
5
5
  "description": "Framework for building generic devframes",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",