zuby 1.0.37 → 1.0.38
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/config.js +0 -6
- package/package.json +1 -1
- package/server/index.js +20 -11
- package/server/zubyRenderer.d.ts +1 -1
- package/server/zubyRenderer.js +19 -14
- package/templates/pathUtils.d.ts +1 -0
- package/templates/pathUtils.js +2 -1
package/config.js
CHANGED
|
@@ -114,12 +114,6 @@ export const mergeDefaultConfig = async (config) => {
|
|
|
114
114
|
config.vite.build.ssrManifest = config.vite.build.ssrManifest ?? 'chunks-manifest.json';
|
|
115
115
|
config.vite.build.ssrEmitAssets = config.vite.build.ssrEmitAssets ?? true;
|
|
116
116
|
config.vite.optimizeDeps = config.vite.optimizeDeps ?? {};
|
|
117
|
-
config.vite.optimizeDeps = {
|
|
118
|
-
...config.vite.optimizeDeps,
|
|
119
|
-
entries: ['**/*', ...(config.vite.optimizeDeps?.entries ?? [])],
|
|
120
|
-
include: ['**/*', ...(config.vite.optimizeDeps?.include ?? [])],
|
|
121
|
-
disabled: false,
|
|
122
|
-
};
|
|
123
117
|
// Merge built-in plugins with user plugins
|
|
124
118
|
config.vite.plugins = [
|
|
125
119
|
...getBuiltInPlugins(),
|
package/package.json
CHANGED
package/server/index.js
CHANGED
|
@@ -8366,7 +8366,7 @@ var TEMPLATES = {
|
|
|
8366
8366
|
|
|
8367
8367
|
// src/templates/pathUtils.ts
|
|
8368
8368
|
function findMatchingTemplate(templates, path2) {
|
|
8369
|
-
for (const template of templates) {
|
|
8369
|
+
for (const [index, template] of templates.entries()) {
|
|
8370
8370
|
const match2 = template.pathRegex.exec(path2);
|
|
8371
8371
|
if (!match2)
|
|
8372
8372
|
continue;
|
|
@@ -8379,6 +8379,7 @@ function findMatchingTemplate(templates, path2) {
|
|
|
8379
8379
|
);
|
|
8380
8380
|
return {
|
|
8381
8381
|
template,
|
|
8382
|
+
index,
|
|
8382
8383
|
params: matchedParams
|
|
8383
8384
|
};
|
|
8384
8385
|
}
|
|
@@ -8415,15 +8416,23 @@ var ZubyRenderer = class {
|
|
|
8415
8416
|
this.renderToString = this.zubyContext.renderToString;
|
|
8416
8417
|
this.renderToStream = this.zubyContext.renderToStream;
|
|
8417
8418
|
}
|
|
8418
|
-
async
|
|
8419
|
-
|
|
8420
|
-
const
|
|
8421
|
-
|
|
8422
|
-
|
|
8423
|
-
|
|
8424
|
-
|
|
8425
|
-
|
|
8426
|
-
|
|
8419
|
+
async executeHandlers(pageContext) {
|
|
8420
|
+
let handlers = [...this.zubyContext?.templates?.handlers || []];
|
|
8421
|
+
const next = async () => {
|
|
8422
|
+
const {
|
|
8423
|
+
template: handler,
|
|
8424
|
+
index = 0,
|
|
8425
|
+
params
|
|
8426
|
+
} = findMatchingTemplate(handlers, pageContext.url.pathname);
|
|
8427
|
+
if (!handler)
|
|
8428
|
+
return;
|
|
8429
|
+
handlers = handlers.slice(index + 1);
|
|
8430
|
+
pageContext.params = params;
|
|
8431
|
+
const handlerModule = await handler?.component();
|
|
8432
|
+
const handlerFunction = handlerModule.default || handlerModule;
|
|
8433
|
+
return handlerFunction(pageContext, next);
|
|
8434
|
+
};
|
|
8435
|
+
return next();
|
|
8427
8436
|
}
|
|
8428
8437
|
async executeProps(pageContext) {
|
|
8429
8438
|
const propsHeader = pageContext.request?.headers.get("x-zuby-props");
|
|
@@ -8509,7 +8518,7 @@ var ZubyRenderer = class {
|
|
|
8509
8518
|
}
|
|
8510
8519
|
async render(req) {
|
|
8511
8520
|
const pageContext = this.createPageContext(req);
|
|
8512
|
-
return await this.
|
|
8521
|
+
return await this.executeHandlers(pageContext) || await this.executeProps(pageContext) || await this.executeEntry(pageContext);
|
|
8513
8522
|
}
|
|
8514
8523
|
};
|
|
8515
8524
|
|
package/server/zubyRenderer.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export default class ZubyRenderer {
|
|
|
16
16
|
constructor(outDir: string);
|
|
17
17
|
reload(): Promise<void>;
|
|
18
18
|
init(): Promise<void>;
|
|
19
|
-
|
|
19
|
+
executeHandlers(pageContext: ZubyPageContext): Promise<undefined | Response>;
|
|
20
20
|
executeProps(pageContext: ZubyPageContext): Promise<undefined | Response>;
|
|
21
21
|
executeEntry(pageContext: ZubyPageContext): Promise<Response>;
|
|
22
22
|
createPageContext(req: Request): ZubyPageContext;
|
package/server/zubyRenderer.js
CHANGED
|
@@ -32,19 +32,24 @@ export default class ZubyRenderer {
|
|
|
32
32
|
this.renderToString = this.zubyContext.renderToString;
|
|
33
33
|
this.renderToStream = this.zubyContext.renderToStream;
|
|
34
34
|
}
|
|
35
|
-
async
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
35
|
+
async executeHandlers(pageContext) {
|
|
36
|
+
let handlers = [...(this.zubyContext?.templates?.handlers || [])];
|
|
37
|
+
const next = async () => {
|
|
38
|
+
const { template: handler, index = 0, params, } = findMatchingTemplate(handlers, pageContext.url.pathname);
|
|
39
|
+
// Nothing to execute if no handler was found
|
|
40
|
+
if (!handler)
|
|
41
|
+
return;
|
|
42
|
+
// Remove all handlers before the matched one
|
|
43
|
+
handlers = handlers.slice(index + 1);
|
|
44
|
+
// Assign matched params to pageContext. Handler can have different params than the page.
|
|
45
|
+
pageContext.params = params;
|
|
46
|
+
// Load and find module default export
|
|
47
|
+
const handlerModule = await handler?.component();
|
|
48
|
+
const handlerFunction = handlerModule.default || handlerModule;
|
|
49
|
+
// Execute the handler function
|
|
50
|
+
return handlerFunction(pageContext, next);
|
|
51
|
+
};
|
|
52
|
+
return next();
|
|
48
53
|
}
|
|
49
54
|
async executeProps(pageContext) {
|
|
50
55
|
const propsHeader = pageContext.request?.headers.get('x-zuby-props');
|
|
@@ -143,7 +148,7 @@ export default class ZubyRenderer {
|
|
|
143
148
|
}
|
|
144
149
|
async render(req) {
|
|
145
150
|
const pageContext = this.createPageContext(req);
|
|
146
|
-
return ((await this.
|
|
151
|
+
return ((await this.executeHandlers(pageContext)) ||
|
|
147
152
|
(await this.executeProps(pageContext)) ||
|
|
148
153
|
(await this.executeEntry(pageContext)));
|
|
149
154
|
}
|
package/templates/pathUtils.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { LazyTemplate, Template } from './types.js';
|
|
|
4
4
|
*/
|
|
5
5
|
export declare function findMatchingTemplate<T extends Template | LazyTemplate>(templates: T[], path: string): {
|
|
6
6
|
template?: T;
|
|
7
|
+
index?: number;
|
|
7
8
|
params: Record<string, string>;
|
|
8
9
|
};
|
|
9
10
|
export declare const pathToRegexp: (pathPattern: string) => {
|
package/templates/pathUtils.js
CHANGED
|
@@ -3,7 +3,7 @@ import { BASE_TEMPLATES } from './types.js';
|
|
|
3
3
|
* Returns the matching template for the given path.
|
|
4
4
|
*/
|
|
5
5
|
export function findMatchingTemplate(templates, path) {
|
|
6
|
-
for (const template of templates) {
|
|
6
|
+
for (const [index, template] of templates.entries()) {
|
|
7
7
|
const match = template.pathRegex.exec(path);
|
|
8
8
|
if (!match)
|
|
9
9
|
continue;
|
|
@@ -13,6 +13,7 @@ export function findMatchingTemplate(templates, path) {
|
|
|
13
13
|
}, {});
|
|
14
14
|
return {
|
|
15
15
|
template,
|
|
16
|
+
index,
|
|
16
17
|
params: matchedParams,
|
|
17
18
|
};
|
|
18
19
|
}
|