vatts 2.2.5 → 2.3.0-canary
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/README.md +3 -3
- package/dist/builder.js +54 -17
- package/dist/frameworks/FrontCore.d.ts +34 -0
- package/dist/frameworks/FrontCore.js +128 -0
- package/dist/{vue → frameworks/builds}/vue.build.js +1 -1
- package/dist/frameworks/react/client.d.ts +8 -0
- package/dist/{react → frameworks/react}/client.js +14 -14
- package/dist/{react → frameworks/react/components}/Link.js +2 -2
- package/dist/frameworks/react/entry.client.d.ts +14 -0
- package/dist/frameworks/react/entry.client.js +211 -0
- package/dist/frameworks/react/react-elements.d.ts +10 -0
- package/dist/{react → frameworks/renderers}/renderer-react.d.ts +2 -2
- package/dist/{react → frameworks/renderers}/renderer-react.js +34 -68
- package/dist/{vue → frameworks/renderers}/renderer.vue.d.ts +2 -2
- package/dist/frameworks/renderers/renderer.vue.js +193 -0
- package/dist/frameworks/themes/BuildingPage.d.ts +1 -0
- package/dist/frameworks/themes/BuildingPage.js +312 -0
- package/dist/frameworks/themes/DefaultNotFound.d.ts +1 -0
- package/dist/frameworks/themes/DefaultNotFound.js +330 -0
- package/dist/frameworks/themes/ErrorModal.d.ts +1 -0
- package/dist/frameworks/themes/ErrorModal.js +345 -0
- package/dist/frameworks/themes/ServerError.d.ts +1 -0
- package/dist/frameworks/themes/ServerError.js +401 -0
- package/dist/frameworks/themes/VattsDevBadge.d.ts +1 -0
- package/dist/frameworks/themes/VattsDevBadge.js +232 -0
- package/dist/frameworks/vue/App.vue +149 -0
- package/dist/frameworks/vue/client.d.ts +9 -0
- package/dist/{vue → frameworks/vue}/client.js +13 -11
- package/dist/{vue → frameworks/vue/components}/Link.vue +1 -1
- package/dist/frameworks/vue/entry.client.js +75 -0
- package/dist/global/global.d.ts +1 -2
- package/dist/index.js +12 -1
- package/dist/renderer.js +2 -2
- package/package.json +10 -26
- package/dist/react/BuildingPage.d.ts +0 -2
- package/dist/react/BuildingPage.js +0 -270
- package/dist/react/DefaultNotFound.d.ts +0 -2
- package/dist/react/DefaultNotFound.js +0 -248
- package/dist/react/DevIndicator.d.ts +0 -5
- package/dist/react/DevIndicator.js +0 -203
- package/dist/react/ErrorModal.d.ts +0 -20
- package/dist/react/ErrorModal.js +0 -266
- package/dist/react/client.d.ts +0 -8
- package/dist/react/entry.client.d.ts +0 -6
- package/dist/react/entry.client.js +0 -325
- package/dist/react/server-error.d.ts +0 -8
- package/dist/react/server-error.js +0 -346
- package/dist/vue/App.vue +0 -199
- package/dist/vue/BuildingPage.vue +0 -281
- package/dist/vue/DefaultNotFound.vue +0 -329
- package/dist/vue/DevIndicator.vue +0 -226
- package/dist/vue/ErrorModal.vue +0 -317
- package/dist/vue/client.d.ts +0 -9
- package/dist/vue/entry.client.js +0 -110
- package/dist/vue/renderer.vue.js +0 -387
- package/dist/vue/server-error.vue +0 -351
- /package/dist/{react → frameworks/builds}/react.build.d.ts +0 -0
- /package/dist/{react → frameworks/builds}/react.build.js +0 -0
- /package/dist/{vue → frameworks/builds}/vue.build.d.ts +0 -0
- /package/dist/{react → frameworks/react/components}/Link.d.ts +0 -0
- /package/dist/{react → frameworks/react/components}/image/Image.d.ts +0 -0
- /package/dist/{react → frameworks/react/components}/image/Image.js +0 -0
- /package/dist/{vue → frameworks/vue/components}/image/Image.vue +0 -0
- /package/dist/{vue → frameworks/vue}/entry.client.d.ts +0 -0
package/dist/vue/renderer.vue.js
DELETED
|
@@ -1,387 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.renderVue = renderVue;
|
|
40
|
-
const router_1 = require("../router");
|
|
41
|
-
const fs_1 = __importDefault(require("fs"));
|
|
42
|
-
const path_1 = __importDefault(require("path"));
|
|
43
|
-
const common_1 = require("../renderers/common");
|
|
44
|
-
const vue = __importStar(require("vue"));
|
|
45
|
-
const vueServerRenderer = __importStar(require("@vue/server-renderer"));
|
|
46
|
-
const BuildingPage_vue_1 = __importDefault(require("./BuildingPage.vue"));
|
|
47
|
-
const server_error_vue_1 = __importDefault(require("./server-error.vue"));
|
|
48
|
-
function buildVueShellDocument(options) {
|
|
49
|
-
const { lang, title, metaTagsHtml, scriptPreloadsHtml, componentPreloadsHtml, stylesHtml, obfuscatedData, scriptsHtml, hotReloadScript, bodyInnerHtml, } = options;
|
|
50
|
-
return `<!DOCTYPE html>
|
|
51
|
-
<html lang="${lang}">
|
|
52
|
-
<head>
|
|
53
|
-
<meta charset="utf-8" />
|
|
54
|
-
<title>${title}</title>
|
|
55
|
-
${metaTagsHtml}
|
|
56
|
-
${scriptPreloadsHtml}
|
|
57
|
-
${componentPreloadsHtml}
|
|
58
|
-
${stylesHtml}
|
|
59
|
-
</head>
|
|
60
|
-
<body>
|
|
61
|
-
<script id="__vatts_data__" type="text/plain" data-h="${obfuscatedData}"></script>
|
|
62
|
-
<div id="root">${bodyInnerHtml || ''}</div>
|
|
63
|
-
${scriptsHtml}
|
|
64
|
-
${hotReloadScript ? `<div style="display:none">${hotReloadScript}</div>` : ''}
|
|
65
|
-
</body>
|
|
66
|
-
</html>`;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Garante que o componente Vue esteja carregado e compilado corretamente.
|
|
70
|
-
* Se o loader falhar em trazer o template (render function), compilamos manualmente aqui.
|
|
71
|
-
*/
|
|
72
|
-
function ensureVueComponent(existingComponent, componentPath) {
|
|
73
|
-
let component = existingComponent;
|
|
74
|
-
// 1. Se não temos o componente objeto, tentamos carregar do disco
|
|
75
|
-
if (!component && componentPath) {
|
|
76
|
-
try {
|
|
77
|
-
const module = (0, common_1.requireWithoutStyles)(componentPath);
|
|
78
|
-
component = module.default || module;
|
|
79
|
-
}
|
|
80
|
-
catch (e) {
|
|
81
|
-
console.error(`Error loading component from ${componentPath}:`, e);
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (!component)
|
|
86
|
-
return null;
|
|
87
|
-
// 2. Correção Crítica: Se o componente existe mas não tem render/ssrRender
|
|
88
|
-
// (comum quando o loader processa o script mas esquece o template)
|
|
89
|
-
if (typeof component === 'object' && !component.render && !component.ssrRender && componentPath && componentPath.endsWith('.vue')) {
|
|
90
|
-
try {
|
|
91
|
-
// Requer as dependências de compilação dinamicamente
|
|
92
|
-
let sfc, esbuild;
|
|
93
|
-
try {
|
|
94
|
-
sfc = require('vue/compiler-sfc');
|
|
95
|
-
esbuild = require('esbuild');
|
|
96
|
-
}
|
|
97
|
-
catch (e) {
|
|
98
|
-
// Se não tiver as ferramentas de build, não podemos corrigir
|
|
99
|
-
return component;
|
|
100
|
-
}
|
|
101
|
-
const source = fs_1.default.readFileSync(componentPath, 'utf8');
|
|
102
|
-
const { descriptor } = sfc.parse(source, { filename: componentPath });
|
|
103
|
-
if (descriptor.template) {
|
|
104
|
-
// Tenta obter bindings do script para otimização (opcional, mas bom para setup)
|
|
105
|
-
let bindings;
|
|
106
|
-
if (descriptor.script || descriptor.scriptSetup) {
|
|
107
|
-
try {
|
|
108
|
-
const scriptResult = sfc.compileScript(descriptor, { id: componentPath });
|
|
109
|
-
bindings = scriptResult.bindings;
|
|
110
|
-
}
|
|
111
|
-
catch (e) { /* Ignora erro de script pois já foi processado pelo loader */ }
|
|
112
|
-
}
|
|
113
|
-
// Compila o template especificamente para SSR
|
|
114
|
-
const templateResult = sfc.compileTemplate({
|
|
115
|
-
source: descriptor.template.content,
|
|
116
|
-
filename: componentPath,
|
|
117
|
-
id: componentPath,
|
|
118
|
-
compilerOptions: {
|
|
119
|
-
bindingMetadata: bindings
|
|
120
|
-
},
|
|
121
|
-
ssr: true,
|
|
122
|
-
isProd: false,
|
|
123
|
-
// CORREÇÃO: Passa as variáveis CSS para evitar erro no SSR
|
|
124
|
-
ssrCssVars: descriptor.cssVars || []
|
|
125
|
-
});
|
|
126
|
-
if (templateResult.code) {
|
|
127
|
-
// Transforma o código ESM gerado pelo Vue em CJS para rodar no Node
|
|
128
|
-
const transformed = esbuild.transformSync(templateResult.code, {
|
|
129
|
-
loader: 'js',
|
|
130
|
-
format: 'cjs',
|
|
131
|
-
target: 'node16'
|
|
132
|
-
});
|
|
133
|
-
// Sandbox simples para executar o código do template e extrair a função ssrRender
|
|
134
|
-
const mod = { exports: {} };
|
|
135
|
-
const req = (id) => {
|
|
136
|
-
if (id === 'vue')
|
|
137
|
-
return require('vue');
|
|
138
|
-
if (id === '@vue/server-renderer')
|
|
139
|
-
return require('@vue/server-renderer');
|
|
140
|
-
return require(id);
|
|
141
|
-
};
|
|
142
|
-
const runModule = new Function('module', 'exports', 'require', transformed.code);
|
|
143
|
-
runModule(mod, mod.exports, req);
|
|
144
|
-
// Anexa a função render compilada ao componente existente
|
|
145
|
-
if (mod.exports.ssrRender) {
|
|
146
|
-
component.ssrRender = mod.exports.ssrRender;
|
|
147
|
-
}
|
|
148
|
-
if (mod.exports.render && !component.render) {
|
|
149
|
-
component.render = mod.exports.render;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
catch (e) {
|
|
155
|
-
console.warn(`Failed to manually compile template for ${componentPath}:`, e);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return component;
|
|
159
|
-
}
|
|
160
|
-
async function renderVue({ req, res, route, params, allRoutes }) {
|
|
161
|
-
// ATENÇÃO: Polyfill executado aqui para garantir que window/document existam
|
|
162
|
-
// antes de qualquer lógica de componente ser executada.
|
|
163
|
-
(0, common_1.polyfillBrowserEnv)();
|
|
164
|
-
if (!vue) {
|
|
165
|
-
res.statusCode = 500;
|
|
166
|
-
res.end('Vue dependencies not installed.');
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
if (!vueServerRenderer) {
|
|
170
|
-
res.statusCode = 500;
|
|
171
|
-
res.end('Vue server dependencies not installed.');
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
const { createSSRApp, h } = vue;
|
|
175
|
-
const { renderToNodeStream, renderToString } = vueServerRenderer;
|
|
176
|
-
const { generateMetadata } = route;
|
|
177
|
-
const isProduction = !req.hwebDev;
|
|
178
|
-
const hotReloadManager = req.hotReloadManager;
|
|
179
|
-
let assets = null;
|
|
180
|
-
let metadata = { title: 'Vatts App' };
|
|
181
|
-
let layoutInfo = null;
|
|
182
|
-
const sendShell = async (options) => {
|
|
183
|
-
const includeScripts = options.includeScripts !== false;
|
|
184
|
-
if (!assets) {
|
|
185
|
-
if (!res.headersSent) {
|
|
186
|
-
res.statusCode = options.statusCode;
|
|
187
|
-
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
188
|
-
res.end(isProduction ? '' : '<h1>SSR Error</h1>');
|
|
189
|
-
}
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
const hotReloadScript = includeScripts && !isProduction && hotReloadManager ? hotReloadManager.getClientScript() : '';
|
|
193
|
-
let metaTagsHtml = (() => {
|
|
194
|
-
try {
|
|
195
|
-
return (0, common_1.generateMetaTags)(metadata);
|
|
196
|
-
}
|
|
197
|
-
catch {
|
|
198
|
-
return '';
|
|
199
|
-
}
|
|
200
|
-
})();
|
|
201
|
-
if (!includeScripts) {
|
|
202
|
-
metaTagsHtml = (0, common_1.stripScriptTags)(metaTagsHtml);
|
|
203
|
-
}
|
|
204
|
-
const htmlLang = metadata.language || 'pt-BR';
|
|
205
|
-
const title = metadata.title || 'Vatts.js';
|
|
206
|
-
const scriptPreloadsHtml = includeScripts
|
|
207
|
-
? assets.scripts.map((src) => `<link rel="modulepreload" href="${src}">`).join('\n')
|
|
208
|
-
: '';
|
|
209
|
-
const componentPreloadsHtml = includeScripts
|
|
210
|
-
? (() => {
|
|
211
|
-
try {
|
|
212
|
-
const componentPreloads = (0, common_1.extractComponentPreloads)(route.componentPath ? path_1.default.resolve(process.cwd(), route.componentPath) : '');
|
|
213
|
-
return componentPreloads.join('\n');
|
|
214
|
-
}
|
|
215
|
-
catch {
|
|
216
|
-
return '';
|
|
217
|
-
}
|
|
218
|
-
})()
|
|
219
|
-
: '';
|
|
220
|
-
const stylesHtml = assets.styles.map((styleUrl) => `<link rel="stylesheet" href="${styleUrl}">`).join('\n');
|
|
221
|
-
const scriptsHtml = includeScripts
|
|
222
|
-
? assets.scripts.map((src) => `<script type="module" src="${src}"></script>`).join('\n')
|
|
223
|
-
: '';
|
|
224
|
-
const obfuscatedData = (() => {
|
|
225
|
-
try {
|
|
226
|
-
return (0, common_1.obfuscateData)({
|
|
227
|
-
routes: [],
|
|
228
|
-
initialComponentPath: route.componentPath,
|
|
229
|
-
initialParams: params,
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
catch {
|
|
233
|
-
return '';
|
|
234
|
-
}
|
|
235
|
-
})();
|
|
236
|
-
res.statusCode = options.statusCode;
|
|
237
|
-
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
238
|
-
res.end(buildVueShellDocument({
|
|
239
|
-
lang: htmlLang,
|
|
240
|
-
title,
|
|
241
|
-
metaTagsHtml,
|
|
242
|
-
scriptPreloadsHtml,
|
|
243
|
-
componentPreloadsHtml,
|
|
244
|
-
stylesHtml,
|
|
245
|
-
obfuscatedData,
|
|
246
|
-
scriptsHtml,
|
|
247
|
-
hotReloadScript,
|
|
248
|
-
bodyInnerHtml: options.bodyInnerHtml,
|
|
249
|
-
}));
|
|
250
|
-
};
|
|
251
|
-
const sendSsrError = async (error) => {
|
|
252
|
-
if (isProduction) {
|
|
253
|
-
await sendShell({ bodyInnerHtml: '', statusCode: 200, includeScripts: true });
|
|
254
|
-
return;
|
|
255
|
-
}
|
|
256
|
-
try {
|
|
257
|
-
const ErrorRoot = {
|
|
258
|
-
setup() {
|
|
259
|
-
return () => h(server_error_vue_1.default, {
|
|
260
|
-
error,
|
|
261
|
-
requestUrl: (0, common_1.getRequestUrl)(req),
|
|
262
|
-
hint: 'SSR failed to render this route. See the error below.',
|
|
263
|
-
});
|
|
264
|
-
},
|
|
265
|
-
};
|
|
266
|
-
const errorApp = createSSRApp(ErrorRoot);
|
|
267
|
-
const errorHtml = await renderToString(errorApp);
|
|
268
|
-
await sendShell({ bodyInnerHtml: errorHtml, statusCode: 500, includeScripts: false });
|
|
269
|
-
}
|
|
270
|
-
catch {
|
|
271
|
-
await sendShell({ bodyInnerHtml: '<h1>SSR Error</h1>', statusCode: 500, includeScripts: false });
|
|
272
|
-
}
|
|
273
|
-
};
|
|
274
|
-
try {
|
|
275
|
-
assets = (0, common_1.getBuildAssets)();
|
|
276
|
-
if (!assets || assets.scripts.length === 0) {
|
|
277
|
-
const RootComponent = {
|
|
278
|
-
setup() {
|
|
279
|
-
return () => {
|
|
280
|
-
return BuildingPage_vue_1.default ? h(BuildingPage_vue_1.default, { params }) : h('div', 'Page not found/loaded');
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
};
|
|
284
|
-
const app = createSSRApp(RootComponent);
|
|
285
|
-
// 5. Stream
|
|
286
|
-
const stream = renderToNodeStream(app);
|
|
287
|
-
res.setHeader('Content-Type', 'text/html');
|
|
288
|
-
// enviar stream direto
|
|
289
|
-
stream.pipe(res, { end: false });
|
|
290
|
-
stream.on('end', () => {
|
|
291
|
-
res.end();
|
|
292
|
-
});
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
// 1. Layout (Carrega e Corrige se necessário)
|
|
296
|
-
layoutInfo = (0, router_1.getLayout)();
|
|
297
|
-
let LayoutComponent = null;
|
|
298
|
-
if (layoutInfo) {
|
|
299
|
-
LayoutComponent = ensureVueComponent(null, path_1.default.resolve(process.cwd(), layoutInfo.componentPath));
|
|
300
|
-
}
|
|
301
|
-
// 2. Metadata
|
|
302
|
-
if (layoutInfo && layoutInfo.metadata) {
|
|
303
|
-
metadata = { ...metadata, ...layoutInfo.metadata };
|
|
304
|
-
}
|
|
305
|
-
if (generateMetadata) {
|
|
306
|
-
const routeMetadata = await Promise.resolve(generateMetadata(params, req));
|
|
307
|
-
metadata = { ...metadata, ...routeMetadata };
|
|
308
|
-
}
|
|
309
|
-
// 3. Initial Data
|
|
310
|
-
const results = await Promise.all(allRoutes.map(async (r) => {
|
|
311
|
-
let routeMeta = {};
|
|
312
|
-
if (r.generateMetadata) {
|
|
313
|
-
routeMeta = await r.generateMetadata(params, req);
|
|
314
|
-
}
|
|
315
|
-
if (!routeMeta.title) {
|
|
316
|
-
routeMeta.title = layoutInfo?.metadata.title || 'Vatts App';
|
|
317
|
-
}
|
|
318
|
-
return {
|
|
319
|
-
pattern: r.pattern,
|
|
320
|
-
componentPath: r.componentPath,
|
|
321
|
-
metadata: routeMeta,
|
|
322
|
-
};
|
|
323
|
-
}));
|
|
324
|
-
const initialData = {
|
|
325
|
-
routes: results,
|
|
326
|
-
initialComponentPath: route.componentPath,
|
|
327
|
-
initialParams: params,
|
|
328
|
-
};
|
|
329
|
-
const obfuscatedData = (0, common_1.obfuscateData)(initialData);
|
|
330
|
-
const hotReloadScript = !isProduction && hotReloadManager ? hotReloadManager.getClientScript() : '';
|
|
331
|
-
const metaTagsHtml = (0, common_1.generateMetaTags)(metadata);
|
|
332
|
-
const htmlLang = metadata.language || 'pt-BR';
|
|
333
|
-
// Otimização: Adiciona modulepreload para scripts principais do bundle
|
|
334
|
-
const scriptPreloadsHtml = assets.scripts.map(src => `<link rel="modulepreload" href="${src}">`).join('\n');
|
|
335
|
-
// Otimização: Intercepta assets do componente atual para preload
|
|
336
|
-
const componentPreloads = (0, common_1.extractComponentPreloads)(route.componentPath ? path_1.default.resolve(process.cwd(), route.componentPath) : '');
|
|
337
|
-
const componentPreloadsHtml = componentPreloads.join('\n');
|
|
338
|
-
const stylesHtml = assets.styles.map(styleUrl => `<link rel="stylesheet" href="${styleUrl}">`).join('\n');
|
|
339
|
-
const scriptsHtml = assets.scripts.map(src => `<script type="module" src="${src}"></script>`).join('\n');
|
|
340
|
-
// 4. Create Vue App
|
|
341
|
-
// Carrega o componente da rota e aplica a correção (compile template) se o loader falhou
|
|
342
|
-
let PageComponent = ensureVueComponent(route.component, route.componentPath ? path_1.default.resolve(process.cwd(), route.componentPath) : '');
|
|
343
|
-
// Componente Root
|
|
344
|
-
const RootComponent = {
|
|
345
|
-
setup() {
|
|
346
|
-
return () => {
|
|
347
|
-
const pageNode = PageComponent ? h(PageComponent, { params }) : h('div', 'Page not found/loaded');
|
|
348
|
-
if (LayoutComponent) {
|
|
349
|
-
return h(LayoutComponent, null, { default: () => pageNode });
|
|
350
|
-
}
|
|
351
|
-
return pageNode;
|
|
352
|
-
};
|
|
353
|
-
}
|
|
354
|
-
};
|
|
355
|
-
const app = createSSRApp(RootComponent);
|
|
356
|
-
// 5. Render (usa renderToString para evitar HTML parcial e permitir fallback)
|
|
357
|
-
try {
|
|
358
|
-
const bodyInnerHtml = await renderToString(app);
|
|
359
|
-
res.statusCode = 200;
|
|
360
|
-
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
361
|
-
res.end(buildVueShellDocument({
|
|
362
|
-
lang: htmlLang,
|
|
363
|
-
title: metadata.title || 'Vatts.js',
|
|
364
|
-
metaTagsHtml,
|
|
365
|
-
scriptPreloadsHtml,
|
|
366
|
-
componentPreloadsHtml,
|
|
367
|
-
stylesHtml,
|
|
368
|
-
obfuscatedData,
|
|
369
|
-
scriptsHtml,
|
|
370
|
-
hotReloadScript,
|
|
371
|
-
bodyInnerHtml,
|
|
372
|
-
}));
|
|
373
|
-
}
|
|
374
|
-
catch (err) {
|
|
375
|
-
if (!isProduction) {
|
|
376
|
-
console.error('Vue SSR Error:', err);
|
|
377
|
-
}
|
|
378
|
-
await sendSsrError(err);
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
catch (err) {
|
|
382
|
-
if (!isProduction) {
|
|
383
|
-
console.error("Critical Vue Render Error:", err);
|
|
384
|
-
}
|
|
385
|
-
await sendSsrError(err);
|
|
386
|
-
}
|
|
387
|
-
}
|