@mauroandre/velojs 0.0.46 → 0.0.48
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/agent/skills/velojs-loaders/SKILL.md +17 -0
- package/agent/skills/velojs-middlewares/SKILL.md +17 -0
- package/dist/loader-store.js +25 -21
- package/dist/server.d.ts +10 -0
- package/dist/server.js +114 -102
- package/package.json +1 -1
|
@@ -106,6 +106,23 @@ refetch(); // e.g. aggregate counters
|
|
|
106
106
|
|
|
107
107
|
> **Never mirror loader data into a module-level `export let`.** On the server, a module binding is per-process, not per-request — a value stored there belongs to whichever request wrote it last. `Loader`'s server value is an AsyncLocalStorage getter, so it is per-request by construction. That's the whole reason the handle is safe to export.
|
|
108
108
|
|
|
109
|
+
## Redirecting from a loader
|
|
110
|
+
|
|
111
|
+
A loader may return a `Response` to short-circuit rendering — the common case is an auth gate that redirects instead of rendering the page:
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
export const loader = async ({ c }: LoaderArgs) => {
|
|
115
|
+
const user = c.get("user");
|
|
116
|
+
if (!user) return c.redirect("/login"); // no page render, no __PAGE_DATA__
|
|
117
|
+
return { projects: await listProjects(user) };
|
|
118
|
+
};
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
- **Direct load / refresh:** the browser receives the `302` and navigates normally.
|
|
122
|
+
- **SPA navigation:** the `?_data=1` endpoint answers `{ __redirect: "/login" }` and the client does a full navigation (server state — session, cookies — may have changed, so it is not an SPA transition).
|
|
123
|
+
|
|
124
|
+
Any `Response` short-circuits, not only redirects (a `404` JSON, for example). If several loaders return one, the first in route order (layout → leaf) wins.
|
|
125
|
+
|
|
109
126
|
## When to use which
|
|
110
127
|
|
|
111
128
|
| Scenario | Use |
|
|
@@ -141,3 +141,20 @@ export const action_save = async ({ body, c }: ActionArgs<{ name: string }>) =>
|
|
|
141
141
|
```
|
|
142
142
|
|
|
143
143
|
This is the recommended pattern for passing authentication data (current user, permissions, etc) from middleware to your page code.
|
|
144
|
+
|
|
145
|
+
### Typing `c.get()` — ContextVariableMap
|
|
146
|
+
|
|
147
|
+
`c.get("user")` does not compile out of the box: Hono's `Context` only accepts keys declared in `ContextVariableMap`. Augment it once in your app (e.g. in `app/types.d.ts`) and every `c.get`/`c.set` becomes typed — no casts, no helper functions:
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
import type { Usuario } from "./modules/auth/auth.types.js";
|
|
151
|
+
|
|
152
|
+
declare module "hono" {
|
|
153
|
+
interface ContextVariableMap {
|
|
154
|
+
user: Usuario;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
After this, `c.get("user")` returns `Usuario` in middlewares, loaders, and actions, and `c.get("anythingElse")` fails at compile time.
|
|
160
|
+
|
package/dist/loader-store.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { signal as
|
|
2
|
-
const S =
|
|
3
|
-
let
|
|
4
|
-
const l = /* @__PURE__ */ new Map(),
|
|
1
|
+
import { signal as u } from "@preact/signals";
|
|
2
|
+
const S = u(!1), c = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map(), _ = /* @__PURE__ */ new Set(), p = /* @__PURE__ */ new Map();
|
|
3
|
+
let d = /* @__PURE__ */ new Set();
|
|
4
|
+
const l = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new WeakSet();
|
|
5
5
|
let w = !1;
|
|
6
6
|
function E(t) {
|
|
7
7
|
v();
|
|
8
8
|
let e = c.get(t);
|
|
9
|
-
return e || (e =
|
|
9
|
+
return e || (e = u(null), c.set(t, e)), e;
|
|
10
10
|
}
|
|
11
|
-
function
|
|
12
|
-
let e =
|
|
13
|
-
return e || (e =
|
|
11
|
+
function y(t) {
|
|
12
|
+
let e = h.get(t);
|
|
13
|
+
return e || (e = u(!1), h.set(t, e)), e;
|
|
14
14
|
}
|
|
15
15
|
function v() {
|
|
16
16
|
if (w || typeof window > "u") return;
|
|
@@ -20,22 +20,22 @@ function v() {
|
|
|
20
20
|
for (const e of Object.keys(t)) {
|
|
21
21
|
if (e.startsWith("__")) continue;
|
|
22
22
|
let n = c.get(e);
|
|
23
|
-
n || (n =
|
|
23
|
+
n || (n = u(null), c.set(e, n)), n.value = t[e];
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
function x(t) {
|
|
27
|
-
if (
|
|
28
|
-
|
|
27
|
+
if (g.has(t)) return;
|
|
28
|
+
g.add(t);
|
|
29
29
|
const e = (n) => {
|
|
30
30
|
for (const o of n) {
|
|
31
31
|
const i = o.module?.metadata;
|
|
32
|
-
i?.moduleId && i.fullPath !== void 0 && (f.set(i.moduleId, i.fullPath), (!o.children || o.children.length === 0) &&
|
|
32
|
+
i?.moduleId && i.fullPath !== void 0 && (f.set(i.moduleId, i.fullPath), (!o.children || o.children.length === 0) && _.add(i.moduleId)), o.children && e(o.children);
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
35
|
if (e(t), typeof window < "u") {
|
|
36
36
|
v();
|
|
37
37
|
for (const n of c.keys()) M(n, window.location.pathname);
|
|
38
|
-
|
|
38
|
+
d = L(window.location.pathname);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
const P = (t) => t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -51,7 +51,7 @@ function m(t, e, n = !1) {
|
|
|
51
51
|
}
|
|
52
52
|
function O(t, e) {
|
|
53
53
|
const n = f.get(t);
|
|
54
|
-
return n === void 0 ? !1 : m(n, e,
|
|
54
|
+
return n === void 0 ? !1 : m(n, e, _.has(t)) !== null;
|
|
55
55
|
}
|
|
56
56
|
function L(t) {
|
|
57
57
|
const e = /* @__PURE__ */ new Set();
|
|
@@ -62,7 +62,7 @@ function L(t) {
|
|
|
62
62
|
function k(t, e) {
|
|
63
63
|
const n = f.get(t);
|
|
64
64
|
if (n === void 0) return null;
|
|
65
|
-
const o = m(n, e,
|
|
65
|
+
const o = m(n, e, _.has(t));
|
|
66
66
|
return o === null ? null : JSON.stringify(o);
|
|
67
67
|
}
|
|
68
68
|
function M(t, e) {
|
|
@@ -77,18 +77,22 @@ function H(t) {
|
|
|
77
77
|
async function $(t, e, n) {
|
|
78
78
|
if (typeof window > "u" || t.length === 0) return;
|
|
79
79
|
const o = H(e);
|
|
80
|
-
for (const a of t)
|
|
80
|
+
for (const a of t) y(a).value = !0;
|
|
81
81
|
let i = n ? l.get(o) : void 0;
|
|
82
82
|
i || (i = fetch(o, { cache: "no-cache" }).then((a) => a.json()), n && (l.set(o, i), i.catch(() => {
|
|
83
83
|
}).then(() => l.delete(o))));
|
|
84
84
|
try {
|
|
85
85
|
const a = await i;
|
|
86
|
+
if (a.__redirect) {
|
|
87
|
+
window.location.href = String(a.__redirect);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
86
90
|
typeof __VELO_BUILD_HASH__ < "u" && a.__buildHash && a.__buildHash !== __VELO_BUILD_HASH__ && (S.value = !0);
|
|
87
91
|
for (const r of t)
|
|
88
92
|
r in a && (E(r).value = a[r], M(r, e));
|
|
89
93
|
} catch {
|
|
90
94
|
} finally {
|
|
91
|
-
for (const a of t)
|
|
95
|
+
for (const a of t) y(a).value = !1;
|
|
92
96
|
}
|
|
93
97
|
}
|
|
94
98
|
function T(t) {
|
|
@@ -97,22 +101,22 @@ function T(t) {
|
|
|
97
101
|
for (const o of c.keys()) {
|
|
98
102
|
if (!n.has(o)) continue;
|
|
99
103
|
const i = k(o, t);
|
|
100
|
-
p.get(o) === i &&
|
|
104
|
+
p.get(o) === i && d.has(o) || e.push(o);
|
|
101
105
|
}
|
|
102
|
-
|
|
106
|
+
d = n, $(e, t, !0);
|
|
103
107
|
}
|
|
104
108
|
function U(t) {
|
|
105
109
|
typeof window > "u" || $([t], window.location.pathname, !1);
|
|
106
110
|
}
|
|
107
111
|
function D() {
|
|
108
|
-
c.clear(),
|
|
112
|
+
c.clear(), h.clear(), f.clear(), _.clear(), p.clear(), d = /* @__PURE__ */ new Set(), l.clear(), w = !1, S.value = !1;
|
|
109
113
|
}
|
|
110
114
|
export {
|
|
111
115
|
D as __resetLoaderStore,
|
|
112
116
|
S as __veloUpdatePending,
|
|
113
117
|
m as extractParams,
|
|
114
118
|
E as loaderEntry,
|
|
115
|
-
|
|
119
|
+
y as loaderLoading,
|
|
116
120
|
U as refetchModule,
|
|
117
121
|
x as registerRoutePatterns,
|
|
118
122
|
T as syncLocation
|
package/dist/server.d.ts
CHANGED
|
@@ -9,6 +9,16 @@ export interface StartServerOptions {
|
|
|
9
9
|
port?: number;
|
|
10
10
|
}
|
|
11
11
|
export declare function addRoutes(fn: (app: Hono) => void | Promise<void>): void;
|
|
12
|
+
/**
|
|
13
|
+
* Serializa dados para injeção num <script> inline. JSON não escapa `<`, então
|
|
14
|
+
* uma string com `</script>` nos dados fecharia a tag no meio — o resto do
|
|
15
|
+
* payload transborda pro documento como HTML e a hidratação quebra (observado
|
|
16
|
+
* em produção com conteúdo de modelo contendo pseudo-tags). `<` é escape
|
|
17
|
+
* JSON/JS válido e decodifica transparente no cliente. Também escapa `>`
|
|
18
|
+
* (defesa para `<!--`) e U+2028/U+2029 (válidos em JSON, quebras de linha em
|
|
19
|
+
* JS antigo).
|
|
20
|
+
*/
|
|
21
|
+
export declare const jsonForScript: (value: unknown) => string;
|
|
12
22
|
export declare const createApp: (routes: AppRoutes) => Promise<Hono>;
|
|
13
23
|
export declare const startServer: (options: StartServerOptions) => Promise<Hono<import("hono/types").BlankEnv, import("hono/types").BlankSchema, "/">>;
|
|
14
24
|
export default createApp;
|
package/dist/server.js
CHANGED
|
@@ -1,79 +1,85 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { Hono as
|
|
3
|
-
import { logger as
|
|
4
|
-
import { trimTrailingSlash as
|
|
5
|
-
import { render as
|
|
6
|
-
import { Router as
|
|
7
|
-
import { AsyncLocalStorage as
|
|
1
|
+
import { jsx as _ } from "preact/jsx-runtime";
|
|
2
|
+
import { Hono as j } from "hono";
|
|
3
|
+
import { logger as E } from "hono/logger";
|
|
4
|
+
import { trimTrailingSlash as T } from "hono/trailing-slash";
|
|
5
|
+
import { render as C } from "preact-render-to-string";
|
|
6
|
+
import { Router as k } from "wouter-preact";
|
|
7
|
+
import { AsyncLocalStorage as A } from "node:async_hooks";
|
|
8
8
|
import { getAppContext as w } from "./app-context.js";
|
|
9
|
-
import { flushPendingStreamRoutes as
|
|
10
|
-
import { registerSocketRoutes as I, injectWebSocketServer as
|
|
11
|
-
const
|
|
12
|
-
globalThis.__veloServerData =
|
|
9
|
+
import { flushPendingStreamRoutes as D, registerStreamHandler as $ } from "./events.js";
|
|
10
|
+
import { registerSocketRoutes as I, injectWebSocketServer as S } from "./sockets.js";
|
|
11
|
+
const P = new A();
|
|
12
|
+
globalThis.__veloServerData = P;
|
|
13
13
|
let v = null;
|
|
14
|
-
function
|
|
14
|
+
function Z(e) {
|
|
15
15
|
if (v) {
|
|
16
16
|
e(v);
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
19
|
w().serverCallbacks.push(e);
|
|
20
20
|
}
|
|
21
|
-
function
|
|
21
|
+
function b(e) {
|
|
22
22
|
v = e;
|
|
23
23
|
const t = w();
|
|
24
24
|
for (const s of t.serverCallbacks) s(e);
|
|
25
25
|
t.serverCallbacks.length = 0;
|
|
26
26
|
}
|
|
27
|
-
function
|
|
27
|
+
function ee(e) {
|
|
28
28
|
w().pendingRoutes.push(e);
|
|
29
29
|
}
|
|
30
|
-
const N = (e, t, s, r) => {
|
|
30
|
+
const N = (e) => JSON.stringify(e).replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029"), O = (e, t, s, r) => {
|
|
31
31
|
if (r && r !== 200 && e.status(r), e.req.query("_data") === "1") {
|
|
32
|
-
const
|
|
33
|
-
return e.json(
|
|
32
|
+
const c = globalThis.__veloBuildHash || void 0, i = s ? { ...s, __buildHash: c } : { __buildHash: c };
|
|
33
|
+
return e.json(i);
|
|
34
34
|
}
|
|
35
|
-
const o = e.req.path, n =
|
|
35
|
+
const o = e.req.path, n = P.run(
|
|
36
36
|
s ?? {},
|
|
37
|
-
() =>
|
|
37
|
+
() => C(/* @__PURE__ */ _(k, { ssrPath: o, children: t }))
|
|
38
38
|
);
|
|
39
39
|
if (e.header("Cache-Control", "no-cache"), !s)
|
|
40
40
|
return e.html(n);
|
|
41
|
-
const a = `<script>window.__PAGE_DATA__=${
|
|
42
|
-
s
|
|
43
|
-
)}<\/script>`;
|
|
41
|
+
const a = `<script>window.__PAGE_DATA__=${N(s)}<\/script>`;
|
|
44
42
|
return e.html(n.replace("</head>", `${a}</head>`));
|
|
45
|
-
},
|
|
43
|
+
}, G = async (e, t) => {
|
|
46
44
|
const s = t.req.param(), r = t.req.query(), o = { params: s, query: r, c: t }, n = await Promise.all(
|
|
47
45
|
e.map(async (i) => {
|
|
48
46
|
if (!i.loader) return null;
|
|
49
|
-
const l = await i.loader(o),
|
|
50
|
-
return
|
|
47
|
+
const l = await i.loader(o), d = i.metadata?.moduleId;
|
|
48
|
+
return d ? { moduleId: d, loaderData: l } : null;
|
|
51
49
|
})
|
|
52
|
-
)
|
|
50
|
+
);
|
|
51
|
+
let a;
|
|
52
|
+
for (const i of n)
|
|
53
|
+
if (i && i.loaderData instanceof Response) {
|
|
54
|
+
a = i.loaderData;
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
const c = {
|
|
53
58
|
__params: s,
|
|
54
59
|
__query: r,
|
|
55
60
|
__pathname: t.req.path
|
|
56
61
|
};
|
|
57
62
|
for (const i of n)
|
|
58
|
-
i && (
|
|
63
|
+
i && !(i.loaderData instanceof Response) && (c[i.moduleId] = i.loaderData);
|
|
59
64
|
return {
|
|
60
65
|
components: e.map((i) => i.Component),
|
|
61
|
-
data:
|
|
66
|
+
data: c,
|
|
67
|
+
shortCircuit: a
|
|
62
68
|
};
|
|
63
|
-
},
|
|
69
|
+
}, H = (e) => {
|
|
64
70
|
if (e.length === 0) return null;
|
|
65
71
|
const t = e.filter(Boolean);
|
|
66
72
|
if (t.length === 0) return null;
|
|
67
73
|
if (t.length === 1) {
|
|
68
74
|
const o = t[0];
|
|
69
|
-
return /* @__PURE__ */
|
|
75
|
+
return /* @__PURE__ */ _(o, {});
|
|
70
76
|
}
|
|
71
77
|
const s = t[t.length - 1];
|
|
72
|
-
return t.slice(0, -1).reduceRight((o, n) => /* @__PURE__ */
|
|
73
|
-
},
|
|
78
|
+
return t.slice(0, -1).reduceRight((o, n) => /* @__PURE__ */ _(n, { children: o }), /* @__PURE__ */ _(s, {}));
|
|
79
|
+
}, y = (e, t, s = [], r = []) => {
|
|
74
80
|
for (const o of t) {
|
|
75
81
|
if (o.handler && !o.module) {
|
|
76
|
-
o.children &&
|
|
82
|
+
o.children && y(
|
|
77
83
|
e,
|
|
78
84
|
o.children,
|
|
79
85
|
s,
|
|
@@ -86,29 +92,34 @@ const N = (e, t, s, r) => {
|
|
|
86
92
|
...o.middlewares || []
|
|
87
93
|
];
|
|
88
94
|
if (o.children)
|
|
89
|
-
|
|
95
|
+
y(
|
|
90
96
|
e,
|
|
91
97
|
o.children,
|
|
92
98
|
n,
|
|
93
99
|
a
|
|
94
100
|
);
|
|
95
101
|
else if (o.module) {
|
|
96
|
-
const
|
|
97
|
-
if (!
|
|
102
|
+
const c = o.path === "*", i = o.statusCode ?? (c ? 404 : void 0), l = o.module.metadata?.fullPath;
|
|
103
|
+
if (!l && !c) {
|
|
98
104
|
console.warn(
|
|
99
105
|
`Module ${o.module.metadata?.moduleId} has no fullPath`
|
|
100
106
|
);
|
|
101
107
|
continue;
|
|
102
108
|
}
|
|
103
|
-
const
|
|
104
|
-
const { components:
|
|
105
|
-
|
|
109
|
+
const d = async (h) => {
|
|
110
|
+
const { components: u, data: m, shortCircuit: f } = await G(n, h);
|
|
111
|
+
if (f) {
|
|
112
|
+
const g = f.headers.get("Location");
|
|
113
|
+
return h.req.query("_data") === "1" && g && f.status >= 300 && f.status < 400 ? h.json({ __redirect: g }) : f;
|
|
114
|
+
}
|
|
115
|
+
const p = H(u);
|
|
116
|
+
return O(h, p, m, i);
|
|
106
117
|
};
|
|
107
|
-
|
|
118
|
+
c ? e.notFound(d) : a.length > 0 ? e.on(["GET"], [l], ...a, d) : e.on(["GET"], [l], d);
|
|
108
119
|
} else
|
|
109
120
|
continue;
|
|
110
121
|
}
|
|
111
|
-
},
|
|
122
|
+
}, q = (e, t, s = []) => {
|
|
112
123
|
for (const r of t) {
|
|
113
124
|
const o = r.module?.metadata?.moduleId, n = [
|
|
114
125
|
...s,
|
|
@@ -116,71 +127,71 @@ const N = (e, t, s, r) => {
|
|
|
116
127
|
];
|
|
117
128
|
if (r.module && o) {
|
|
118
129
|
const a = Object.keys(r.module).filter(
|
|
119
|
-
(
|
|
130
|
+
(c) => c.startsWith("action_")
|
|
120
131
|
);
|
|
121
|
-
for (const
|
|
122
|
-
const
|
|
123
|
-
if (typeof
|
|
124
|
-
const
|
|
132
|
+
for (const c of a) {
|
|
133
|
+
const i = c.replace("action_", ""), l = r.module[c];
|
|
134
|
+
if (typeof l == "function") {
|
|
135
|
+
const d = `/_action/${o}/${i}`, h = async (u) => {
|
|
125
136
|
let m = {};
|
|
126
137
|
try {
|
|
127
|
-
m = await
|
|
138
|
+
m = await u.req.json();
|
|
128
139
|
} catch {
|
|
129
140
|
}
|
|
130
141
|
const f = {
|
|
131
142
|
body: m,
|
|
132
|
-
params:
|
|
133
|
-
query:
|
|
134
|
-
c:
|
|
143
|
+
params: u.req.param(),
|
|
144
|
+
query: u.req.query(),
|
|
145
|
+
c: u
|
|
135
146
|
};
|
|
136
147
|
try {
|
|
137
|
-
const p = await
|
|
138
|
-
return
|
|
148
|
+
const p = await l(f);
|
|
149
|
+
return u.json(p ?? { ok: !0 });
|
|
139
150
|
} catch (p) {
|
|
140
|
-
const
|
|
141
|
-
return
|
|
151
|
+
const g = p instanceof Error ? p.message : "Action failed";
|
|
152
|
+
return u.json({ error: g }, 500);
|
|
142
153
|
}
|
|
143
154
|
};
|
|
144
155
|
n.length > 0 ? e.on(
|
|
145
156
|
["POST"],
|
|
146
|
-
[
|
|
157
|
+
[d],
|
|
147
158
|
...n,
|
|
148
159
|
h
|
|
149
|
-
) : e.on(["POST"], [
|
|
160
|
+
) : e.on(["POST"], [d], h);
|
|
150
161
|
}
|
|
151
162
|
}
|
|
152
163
|
}
|
|
153
|
-
r.children &&
|
|
164
|
+
r.children && q(e, r.children, n);
|
|
154
165
|
}
|
|
155
|
-
},
|
|
166
|
+
}, x = async (e, t, s = []) => {
|
|
156
167
|
const r = (o, n) => {
|
|
157
168
|
for (const a of o) {
|
|
158
|
-
const
|
|
169
|
+
const c = a.module?.metadata?.moduleId, i = [
|
|
159
170
|
...n,
|
|
160
171
|
...a.middlewares || []
|
|
161
172
|
];
|
|
162
|
-
if (a.module &&
|
|
163
|
-
const
|
|
164
|
-
(
|
|
173
|
+
if (a.module && c) {
|
|
174
|
+
const l = Object.keys(a.module).filter(
|
|
175
|
+
(d) => d.startsWith("stream_")
|
|
165
176
|
);
|
|
166
|
-
for (const
|
|
167
|
-
const h =
|
|
168
|
-
if (
|
|
169
|
-
const m = `/_event/${
|
|
170
|
-
|
|
177
|
+
for (const d of l) {
|
|
178
|
+
const h = d.replace("stream_", ""), u = a.module[d];
|
|
179
|
+
if (u?.__isVeloEventStream) {
|
|
180
|
+
const m = `/_event/${c}/${h}`;
|
|
181
|
+
u.__path = m, $(
|
|
171
182
|
e,
|
|
172
183
|
m,
|
|
173
|
-
|
|
174
|
-
|
|
184
|
+
u,
|
|
185
|
+
i
|
|
175
186
|
);
|
|
176
187
|
}
|
|
177
188
|
}
|
|
178
189
|
}
|
|
179
|
-
a.children && r(a.children,
|
|
190
|
+
a.children && r(a.children, i);
|
|
180
191
|
}
|
|
181
192
|
};
|
|
182
193
|
r(t, s);
|
|
183
|
-
},
|
|
194
|
+
}, V = (e, t) => t ? t.startsWith("/") ? e + t : e ? e + "/" + t : "/" + t : e || "", W = (e) => {
|
|
184
195
|
const t = /* @__PURE__ */ new Set(), s = (r) => {
|
|
185
196
|
for (const o of r) {
|
|
186
197
|
if (o.module && !o.children) {
|
|
@@ -191,68 +202,69 @@ const N = (e, t, s, r) => {
|
|
|
191
202
|
}
|
|
192
203
|
};
|
|
193
204
|
return s(e), t;
|
|
194
|
-
},
|
|
205
|
+
}, R = (e, t, s, r = "", o = []) => {
|
|
195
206
|
for (const n of t) {
|
|
196
|
-
const a =
|
|
207
|
+
const a = V(r, n.path), c = [
|
|
197
208
|
...o,
|
|
198
209
|
...n.middlewares || []
|
|
199
|
-
],
|
|
200
|
-
if (
|
|
210
|
+
], i = !!n.handler, l = !!n.method;
|
|
211
|
+
if (i && !l ? console.warn(
|
|
201
212
|
`[velojs] invalid route at "${a || "/"}" — "handler" set without "method"; endpoint skipped`
|
|
202
|
-
) :
|
|
213
|
+
) : l && !i ? console.warn(
|
|
203
214
|
`[velojs] invalid route at "${a || "/"}" — "method" set without "handler"; endpoint skipped`
|
|
204
|
-
) :
|
|
215
|
+
) : i && n.module ? console.warn(
|
|
205
216
|
`[velojs] ambiguous route at "${a || "/"}" — both "module" and "handler" set; endpoint ignored, page kept`
|
|
206
|
-
) :
|
|
217
|
+
) : i && n.isRoot && console.warn(
|
|
207
218
|
`[velojs] "isRoot" has no effect on endpoint at "${a || "/"}"; ignored`
|
|
208
|
-
),
|
|
219
|
+
), i && l && !n.module) {
|
|
209
220
|
const h = n.method;
|
|
210
221
|
h === "GET" && s.has(a) && console.warn(
|
|
211
222
|
`[velojs] path "${a}" has both a page GET and an endpoint GET; the page wins and the endpoint is unreachable. Consider renaming one.`
|
|
212
223
|
);
|
|
213
|
-
const
|
|
224
|
+
const u = n.handler, m = async (f) => await u({
|
|
214
225
|
c: f,
|
|
215
226
|
params: f.req.param(),
|
|
216
227
|
query: f.req.query()
|
|
217
228
|
});
|
|
218
|
-
|
|
229
|
+
c.length > 0 ? e.on([h], [a], ...c, m) : e.on([h], [a], m);
|
|
219
230
|
}
|
|
220
|
-
n.children &&
|
|
231
|
+
n.children && R(
|
|
221
232
|
e,
|
|
222
233
|
n.children,
|
|
223
234
|
s,
|
|
224
235
|
a,
|
|
225
|
-
|
|
236
|
+
c
|
|
226
237
|
);
|
|
227
238
|
}
|
|
228
|
-
},
|
|
229
|
-
const t = new
|
|
230
|
-
t.use(
|
|
239
|
+
}, K = async (e) => {
|
|
240
|
+
const t = new j();
|
|
241
|
+
t.use(T()), process.env.NODE_ENV !== "production" && t.use("*", E());
|
|
231
242
|
const r = w().pendingRoutes.splice(0);
|
|
232
243
|
for (const n of r)
|
|
233
244
|
await n(t);
|
|
234
|
-
|
|
235
|
-
const o =
|
|
236
|
-
if (
|
|
245
|
+
y(t, e), q(t, e), await x(t, e);
|
|
246
|
+
const o = W(e);
|
|
247
|
+
if (R(t, e, o), await I(t, e), D(t), process.env.NODE_ENV !== "production" && !v) {
|
|
237
248
|
const n = globalThis.__veloDevServer;
|
|
238
|
-
n && (
|
|
249
|
+
n && (b(n), await S(t, n));
|
|
239
250
|
}
|
|
240
251
|
return t;
|
|
241
|
-
},
|
|
242
|
-
const { routes: t } = e, s = Number(process.env.PORT) || e.port || 3e3, r = await
|
|
252
|
+
}, te = async (e) => {
|
|
253
|
+
const { routes: t } = e, s = Number(process.env.PORT) || e.port || 3e3, r = await K(t);
|
|
243
254
|
if (process.env.NODE_ENV === "production" && !process.env.VELO_STATIC) {
|
|
244
|
-
const { serve: o } = await import("@hono/node-server"), { serveStatic: n } = await import("@hono/node-server/serve-static"), { join: a } = await import("node:path"),
|
|
245
|
-
(process.env.STATIC_BASE_URL || "").startsWith("http") || r.use("/*", n({ root:
|
|
246
|
-
const
|
|
247
|
-
await
|
|
255
|
+
const { serve: o } = await import("@hono/node-server"), { serveStatic: n } = await import("@hono/node-server/serve-static"), { join: a } = await import("node:path"), c = a(process.cwd(), "dist/client");
|
|
256
|
+
(process.env.STATIC_BASE_URL || "").startsWith("http") || r.use("/*", n({ root: c })), console.log(`Server running on http://localhost:${s}`);
|
|
257
|
+
const l = o({ fetch: r.fetch, port: s });
|
|
258
|
+
await S(r, l), b(l);
|
|
248
259
|
}
|
|
249
260
|
return r;
|
|
250
261
|
};
|
|
251
262
|
export {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
263
|
+
ee as addRoutes,
|
|
264
|
+
K as createApp,
|
|
265
|
+
K as default,
|
|
266
|
+
N as jsonForScript,
|
|
267
|
+
Z as onServer,
|
|
268
|
+
P as serverDataStorage,
|
|
269
|
+
te as startServer
|
|
258
270
|
};
|