@mauroandre/velojs 0.0.47 → 0.0.49
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/server.d.ts +10 -0
- package/dist/server.js +24 -25
- package/dist/static.js +1 -1
- package/package.json +1 -1
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
|
@@ -11,7 +11,7 @@ import { registerSocketRoutes as I, injectWebSocketServer as S } from "./sockets
|
|
|
11
11
|
const P = new A();
|
|
12
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;
|
|
@@ -24,10 +24,10 @@ function b(e) {
|
|
|
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
32
|
const c = globalThis.__veloBuildHash || void 0, i = s ? { ...s, __buildHash: c } : { __buildHash: c };
|
|
33
33
|
return e.json(i);
|
|
@@ -38,11 +38,9 @@ const N = (e, t, s, r) => {
|
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
return e.html(n.replace("</head>", `${a}</head>`));
|
|
45
|
-
}, O = async (e, t) => {
|
|
41
|
+
const a = `<script>window.__PAGE_DATA__=${N(s)}<\/script>`;
|
|
42
|
+
return e.html(n.replace("</head>", () => `${a}</head>`));
|
|
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;
|
|
@@ -68,7 +66,7 @@ const N = (e, t, s, r) => {
|
|
|
68
66
|
data: c,
|
|
69
67
|
shortCircuit: a
|
|
70
68
|
};
|
|
71
|
-
},
|
|
69
|
+
}, H = (e) => {
|
|
72
70
|
if (e.length === 0) return null;
|
|
73
71
|
const t = e.filter(Boolean);
|
|
74
72
|
if (t.length === 0) return null;
|
|
@@ -109,13 +107,13 @@ const N = (e, t, s, r) => {
|
|
|
109
107
|
continue;
|
|
110
108
|
}
|
|
111
109
|
const d = async (h) => {
|
|
112
|
-
const { components: u, data: m, shortCircuit: f } = await
|
|
110
|
+
const { components: u, data: m, shortCircuit: f } = await G(n, h);
|
|
113
111
|
if (f) {
|
|
114
112
|
const g = f.headers.get("Location");
|
|
115
113
|
return h.req.query("_data") === "1" && g && f.status >= 300 && f.status < 400 ? h.json({ __redirect: g }) : f;
|
|
116
114
|
}
|
|
117
|
-
const p =
|
|
118
|
-
return
|
|
115
|
+
const p = H(u);
|
|
116
|
+
return O(h, p, m, i);
|
|
119
117
|
};
|
|
120
118
|
c ? e.notFound(d) : a.length > 0 ? e.on(["GET"], [l], ...a, d) : e.on(["GET"], [l], d);
|
|
121
119
|
} else
|
|
@@ -165,7 +163,7 @@ const N = (e, t, s, r) => {
|
|
|
165
163
|
}
|
|
166
164
|
r.children && q(e, r.children, n);
|
|
167
165
|
}
|
|
168
|
-
},
|
|
166
|
+
}, x = async (e, t, s = []) => {
|
|
169
167
|
const r = (o, n) => {
|
|
170
168
|
for (const a of o) {
|
|
171
169
|
const c = a.module?.metadata?.moduleId, i = [
|
|
@@ -193,7 +191,7 @@ const N = (e, t, s, r) => {
|
|
|
193
191
|
}
|
|
194
192
|
};
|
|
195
193
|
r(t, s);
|
|
196
|
-
},
|
|
194
|
+
}, V = (e, t) => t ? t.startsWith("/") ? e + t : e ? e + "/" + t : "/" + t : e || "", W = (e) => {
|
|
197
195
|
const t = /* @__PURE__ */ new Set(), s = (r) => {
|
|
198
196
|
for (const o of r) {
|
|
199
197
|
if (o.module && !o.children) {
|
|
@@ -206,7 +204,7 @@ const N = (e, t, s, r) => {
|
|
|
206
204
|
return s(e), t;
|
|
207
205
|
}, R = (e, t, s, r = "", o = []) => {
|
|
208
206
|
for (const n of t) {
|
|
209
|
-
const a =
|
|
207
|
+
const a = V(r, n.path), c = [
|
|
210
208
|
...o,
|
|
211
209
|
...n.middlewares || []
|
|
212
210
|
], i = !!n.handler, l = !!n.method;
|
|
@@ -238,21 +236,21 @@ const N = (e, t, s, r) => {
|
|
|
238
236
|
c
|
|
239
237
|
);
|
|
240
238
|
}
|
|
241
|
-
},
|
|
239
|
+
}, K = async (e) => {
|
|
242
240
|
const t = new j();
|
|
243
241
|
t.use(T()), process.env.NODE_ENV !== "production" && t.use("*", E());
|
|
244
242
|
const r = w().pendingRoutes.splice(0);
|
|
245
243
|
for (const n of r)
|
|
246
244
|
await n(t);
|
|
247
|
-
y(t, e), q(t, e), await
|
|
248
|
-
const o =
|
|
245
|
+
y(t, e), q(t, e), await x(t, e);
|
|
246
|
+
const o = W(e);
|
|
249
247
|
if (R(t, e, o), await I(t, e), D(t), process.env.NODE_ENV !== "production" && !v) {
|
|
250
248
|
const n = globalThis.__veloDevServer;
|
|
251
249
|
n && (b(n), await S(t, n));
|
|
252
250
|
}
|
|
253
251
|
return t;
|
|
254
|
-
},
|
|
255
|
-
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);
|
|
256
254
|
if (process.env.NODE_ENV === "production" && !process.env.VELO_STATIC) {
|
|
257
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");
|
|
258
256
|
(process.env.STATIC_BASE_URL || "").startsWith("http") || r.use("/*", n({ root: c })), console.log(`Server running on http://localhost:${s}`);
|
|
@@ -262,10 +260,11 @@ const N = (e, t, s, r) => {
|
|
|
262
260
|
return r;
|
|
263
261
|
};
|
|
264
262
|
export {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
263
|
+
ee as addRoutes,
|
|
264
|
+
K as createApp,
|
|
265
|
+
K as default,
|
|
266
|
+
N as jsonForScript,
|
|
267
|
+
Z as onServer,
|
|
269
268
|
P as serverDataStorage,
|
|
270
|
-
|
|
269
|
+
te as startServer
|
|
271
270
|
};
|
package/dist/static.js
CHANGED