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
|
@@ -22,13 +22,14 @@ exports.render = render;
|
|
|
22
22
|
*/
|
|
23
23
|
const react_1 = __importDefault(require("react"));
|
|
24
24
|
const server_1 = require("react-dom/server");
|
|
25
|
-
const
|
|
25
|
+
const router_ts_1 = require("../../router.js");
|
|
26
26
|
const path_1 = __importDefault(require("path"));
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
const
|
|
27
|
+
const common_ts_1 = require("../../renderers/common.js");
|
|
28
|
+
// Importa os geradores de HTML Vanilla
|
|
29
|
+
const BuildingPage_1 = require("../themes/BuildingPage");
|
|
30
|
+
const ServerError_1 = require("../themes/ServerError");
|
|
30
31
|
function buildShellHtml(options) {
|
|
31
|
-
const { lang, title, metaTagsHtml, stylesHtml, hotReloadScript,
|
|
32
|
+
const { lang, title, metaTagsHtml, stylesHtml, hotReloadScript, scriptsHtml } = options;
|
|
32
33
|
return `<!DOCTYPE html>
|
|
33
34
|
<html lang="${lang}">
|
|
34
35
|
<head>
|
|
@@ -38,7 +39,7 @@ function buildShellHtml(options) {
|
|
|
38
39
|
${stylesHtml || ''}
|
|
39
40
|
</head>
|
|
40
41
|
<body>
|
|
41
|
-
|
|
42
|
+
|
|
42
43
|
<div id="root"></div>
|
|
43
44
|
${scriptsHtml || ''}
|
|
44
45
|
${hotReloadScript ? `<div style="display:none">${hotReloadScript}</div>` : ''}
|
|
@@ -46,12 +47,10 @@ function buildShellHtml(options) {
|
|
|
46
47
|
</html>`;
|
|
47
48
|
}
|
|
48
49
|
async function sendReactSsrFallback(options) {
|
|
49
|
-
const { req, res, isProduction, error, assets, lang, title, metaTagsHtml, stylesHtml, hotReloadScript,
|
|
50
|
+
const { req, res, isProduction, error, assets, lang, title, metaTagsHtml, stylesHtml, hotReloadScript, } = options;
|
|
50
51
|
const scriptsHtml = assets.scripts
|
|
51
52
|
.map((src) => `<script type="module" src="${src}"></script>`)
|
|
52
53
|
.join('\n');
|
|
53
|
-
// No DEV a gente remove scripts do head pra garantir que só aparece a página de erro.
|
|
54
|
-
const safeMetaTagsHtmlForDev = (0, common_1.stripScriptTags)(metaTagsHtml);
|
|
55
54
|
if (res.headersSent) {
|
|
56
55
|
try {
|
|
57
56
|
res.end();
|
|
@@ -70,32 +69,26 @@ async function sendReactSsrFallback(options) {
|
|
|
70
69
|
metaTagsHtml,
|
|
71
70
|
stylesHtml,
|
|
72
71
|
hotReloadScript: '',
|
|
73
|
-
obfuscatedData,
|
|
74
72
|
scriptsHtml,
|
|
75
73
|
}));
|
|
76
74
|
return;
|
|
77
75
|
}
|
|
78
|
-
const err = (0,
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
},
|
|
86
|
-
onError() {
|
|
87
|
-
// ignore (já estamos numa tela de erro)
|
|
88
|
-
},
|
|
89
|
-
onShellError() {
|
|
90
|
-
// fallback extremo
|
|
91
|
-
res.end('<h1>SSR Error</h1>');
|
|
92
|
-
resolve();
|
|
93
|
-
},
|
|
94
|
-
});
|
|
76
|
+
const err = (0, common_ts_1.toError)(error);
|
|
77
|
+
// Gera o HTML do Erro via Vanilla JS
|
|
78
|
+
let errorHtml = (0, ServerError_1.getServerErrorHtml)({
|
|
79
|
+
title: title || 'SSR Error',
|
|
80
|
+
error: err,
|
|
81
|
+
requestUrl: (0, common_ts_1.getRequestUrl)(req),
|
|
82
|
+
hint: "SSR failed to render this route. See the error below."
|
|
95
83
|
});
|
|
84
|
+
// Injeta o script de Hot Reload no HTML cru para continuar escutando mudanças
|
|
85
|
+
if (hotReloadScript) {
|
|
86
|
+
errorHtml = errorHtml.replace('</body>', `<div style="display:none">${hotReloadScript}</div></body>`);
|
|
87
|
+
}
|
|
88
|
+
res.end(errorHtml);
|
|
89
|
+
return Promise.resolve();
|
|
96
90
|
}
|
|
97
|
-
function ServerRoot({ lang, title, metaTagsHtml, stylesHtml, initialDataScript, hotReloadScript,
|
|
98
|
-
// Concatena tudo que vai no head em uma única string
|
|
91
|
+
function ServerRoot({ lang, title, metaTagsHtml, stylesHtml, initialDataScript, hotReloadScript, children }) {
|
|
99
92
|
const headContent = `
|
|
100
93
|
<meta charset="utf-8" />
|
|
101
94
|
<title>${title}</title>
|
|
@@ -106,40 +99,31 @@ function ServerRoot({ lang, title, metaTagsHtml, stylesHtml, initialDataScript,
|
|
|
106
99
|
return (react_1.default.createElement("html", { lang: lang },
|
|
107
100
|
react_1.default.createElement("head", { dangerouslySetInnerHTML: { __html: headContent } }),
|
|
108
101
|
react_1.default.createElement("body", null,
|
|
109
|
-
dataScript,
|
|
110
102
|
react_1.default.createElement("div", { id: "root" }, children),
|
|
111
103
|
hotReloadScript && (react_1.default.createElement("div", { style: { display: 'none' }, dangerouslySetInnerHTML: { __html: hotReloadScript } })))));
|
|
112
104
|
}
|
|
113
105
|
async function render({ req, res, route, params, allRoutes }) {
|
|
114
|
-
|
|
115
|
-
// antes de qualquer lógica de componente ser executada.
|
|
116
|
-
(0, common_1.polyfillBrowserEnv)();
|
|
106
|
+
(0, common_ts_1.polyfillBrowserEnv)();
|
|
117
107
|
const { generateMetadata } = route;
|
|
118
108
|
const isProduction = !req.hwebDev;
|
|
119
109
|
const hotReloadManager = req.hotReloadManager;
|
|
120
|
-
// SILENCIAR CONSOLE: Inicia o silêncio para evitar logs de renderização
|
|
121
110
|
let assets = null;
|
|
122
111
|
let metadata = { title: 'Vatts App' };
|
|
123
112
|
let layoutInfo = null;
|
|
124
113
|
try {
|
|
125
|
-
|
|
126
|
-
|
|
114
|
+
assets = (0, common_ts_1.getBuildAssets)();
|
|
115
|
+
// 1. Verificar Build - Envia a página pura em Vanilla JS se não terminou de compilar
|
|
127
116
|
if (!assets || assets.scripts.length === 0) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
131
|
-
pipe(res);
|
|
132
|
-
},
|
|
133
|
-
});
|
|
117
|
+
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
118
|
+
res.end((0, BuildingPage_1.getBuildingScreenHtml)());
|
|
134
119
|
return;
|
|
135
120
|
}
|
|
136
121
|
// 2. Preparar Layout
|
|
137
|
-
layoutInfo = (0,
|
|
122
|
+
layoutInfo = (0, router_ts_1.getLayout)();
|
|
138
123
|
let LayoutComponent = null;
|
|
139
124
|
if (layoutInfo) {
|
|
140
125
|
try {
|
|
141
|
-
|
|
142
|
-
const layoutModule = (0, common_1.requireWithoutStyles)(path_1.default.resolve(process.cwd(), layoutInfo.componentPath));
|
|
126
|
+
const layoutModule = (0, common_ts_1.requireWithoutStyles)(path_1.default.resolve(process.cwd(), layoutInfo.componentPath));
|
|
143
127
|
LayoutComponent = layoutModule.default;
|
|
144
128
|
}
|
|
145
129
|
catch (e) {
|
|
@@ -174,12 +158,9 @@ async function render({ req, res, route, params, allRoutes }) {
|
|
|
174
158
|
initialComponentPath: route.componentPath,
|
|
175
159
|
initialParams: params,
|
|
176
160
|
};
|
|
177
|
-
// Scripts e Estilos
|
|
178
|
-
const obfuscatedData = (0, common_1.obfuscateData)(initialData);
|
|
179
161
|
const hotReloadScript = !isProduction && hotReloadManager ? hotReloadManager.getClientScript() : '';
|
|
180
|
-
const metaTagsHtml = (0,
|
|
162
|
+
const metaTagsHtml = (0, common_ts_1.generateMetaTags)(metadata);
|
|
181
163
|
const htmlLang = metadata.language || 'pt-BR';
|
|
182
|
-
// Gera tags de estilo para o head, garantindo a extensão .css no final para evitar strict MIME checks
|
|
183
164
|
const stylesHtml = assets.styles.map(styleUrl => {
|
|
184
165
|
const [basePath, query] = styleUrl.split('?');
|
|
185
166
|
const finalUrl = !basePath.endsWith('.css') ? `${basePath}.css${query ? `?${query}` : ''}` : styleUrl;
|
|
@@ -187,16 +168,15 @@ async function render({ req, res, route, params, allRoutes }) {
|
|
|
187
168
|
}).join('\n');
|
|
188
169
|
// 5. Componente da Página Atual
|
|
189
170
|
const PageComponent = route.component;
|
|
190
|
-
// Monta a árvore da aplicação
|
|
191
171
|
let AppTree = react_1.default.createElement(PageComponent, { params: params });
|
|
192
172
|
if (LayoutComponent) {
|
|
193
173
|
AppTree = react_1.default.createElement(LayoutComponent, null, AppTree);
|
|
194
174
|
}
|
|
195
|
-
// 6. Streaming
|
|
175
|
+
// 6. Streaming React
|
|
196
176
|
return new Promise((resolve) => {
|
|
197
177
|
let didError = false;
|
|
198
178
|
let firstError = null;
|
|
199
|
-
const stream = (0, server_1.renderToPipeableStream)(react_1.default.createElement(ServerRoot, { lang: htmlLang, title: metadata.title || 'Vatts.js', metaTagsHtml: metaTagsHtml, stylesHtml: stylesHtml, initialDataScript: `/* Data Injection */`, hotReloadScript: hotReloadScript
|
|
179
|
+
const stream = (0, server_1.renderToPipeableStream)(react_1.default.createElement(ServerRoot, { lang: htmlLang, title: metadata.title || 'Vatts.js', metaTagsHtml: metaTagsHtml, stylesHtml: stylesHtml, initialDataScript: `/* Data Injection */`, hotReloadScript: hotReloadScript }, AppTree), {
|
|
200
180
|
bootstrapModules: assets.scripts,
|
|
201
181
|
onAllReady() {
|
|
202
182
|
if (didError) {
|
|
@@ -212,7 +192,6 @@ async function render({ req, res, route, params, allRoutes }) {
|
|
|
212
192
|
metaTagsHtml,
|
|
213
193
|
stylesHtml,
|
|
214
194
|
hotReloadScript,
|
|
215
|
-
obfuscatedData,
|
|
216
195
|
}).then(resolve);
|
|
217
196
|
return;
|
|
218
197
|
}
|
|
@@ -236,11 +215,10 @@ async function render({ req, res, route, params, allRoutes }) {
|
|
|
236
215
|
}
|
|
237
216
|
catch (err) {
|
|
238
217
|
if (!assets) {
|
|
239
|
-
// sem assets não dá pra montar shell completo; evita crash
|
|
240
218
|
if (!res.headersSent) {
|
|
241
219
|
res.statusCode = 500;
|
|
242
220
|
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
243
|
-
res.end(isProduction ? '' : '
|
|
221
|
+
res.end(isProduction ? '' : (0, ServerError_1.getServerErrorHtml)({ error: err, title: 'Critical SSR Error' }));
|
|
244
222
|
}
|
|
245
223
|
return;
|
|
246
224
|
}
|
|
@@ -254,7 +232,7 @@ async function render({ req, res, route, params, allRoutes }) {
|
|
|
254
232
|
title: metadata.title || 'Vatts.js',
|
|
255
233
|
metaTagsHtml: (() => {
|
|
256
234
|
try {
|
|
257
|
-
return (0,
|
|
235
|
+
return (0, common_ts_1.generateMetaTags)(metadata);
|
|
258
236
|
}
|
|
259
237
|
catch {
|
|
260
238
|
return '';
|
|
@@ -266,18 +244,6 @@ async function render({ req, res, route, params, allRoutes }) {
|
|
|
266
244
|
return `<link rel="stylesheet" href="${finalUrl}">`;
|
|
267
245
|
}).join('\n'),
|
|
268
246
|
hotReloadScript: !isProduction && hotReloadManager ? hotReloadManager.getClientScript() : '',
|
|
269
|
-
obfuscatedData: (() => {
|
|
270
|
-
try {
|
|
271
|
-
return (0, common_1.obfuscateData)({
|
|
272
|
-
routes: [],
|
|
273
|
-
initialComponentPath: route.componentPath,
|
|
274
|
-
initialParams: params,
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
catch {
|
|
278
|
-
return '';
|
|
279
|
-
}
|
|
280
|
-
})(),
|
|
281
247
|
});
|
|
282
248
|
}
|
|
283
249
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RouteConfig } from '
|
|
2
|
-
import type { GenericRequest } from '
|
|
1
|
+
import { RouteConfig } from '../../types.ts';
|
|
2
|
+
import type { GenericRequest } from '../../types/framework.ts';
|
|
3
3
|
interface RenderOptions {
|
|
4
4
|
req: GenericRequest;
|
|
5
5
|
res: any;
|
|
@@ -0,0 +1,193 @@
|
|
|
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_ts_1 = require("../../router.js");
|
|
41
|
+
const fs_1 = __importDefault(require("fs"));
|
|
42
|
+
const path_1 = __importDefault(require("path"));
|
|
43
|
+
const common_ts_1 = require("../../renderers/common.js");
|
|
44
|
+
const vue = __importStar(require("vue"));
|
|
45
|
+
const vueServerRenderer = __importStar(require("@vue/server-renderer"));
|
|
46
|
+
// Importa os geradores de HTML Vanilla
|
|
47
|
+
const BuildingPage_1 = require("../themes/BuildingPage");
|
|
48
|
+
const ServerError_1 = require("../themes/ServerError");
|
|
49
|
+
function buildVueShellDocument(options) {
|
|
50
|
+
const { lang, title, metaTagsHtml, scriptPreloadsHtml, componentPreloadsHtml, stylesHtml, obfuscatedData, scriptsHtml, hotReloadScript, bodyInnerHtml, } = options;
|
|
51
|
+
return `<!DOCTYPE html>
|
|
52
|
+
<html lang="${lang}">
|
|
53
|
+
<head>
|
|
54
|
+
<meta charset="utf-8" />
|
|
55
|
+
<title>${title}</title>
|
|
56
|
+
${metaTagsHtml}
|
|
57
|
+
${scriptPreloadsHtml}
|
|
58
|
+
${componentPreloadsHtml}
|
|
59
|
+
${stylesHtml}
|
|
60
|
+
</head>
|
|
61
|
+
<body>
|
|
62
|
+
<script id="__vatts_data__" type="text/plain" data-h="${obfuscatedData}"></script>
|
|
63
|
+
<div id="root">${bodyInnerHtml || ''}</div>
|
|
64
|
+
${scriptsHtml}
|
|
65
|
+
${hotReloadScript ? `<div style="display:none">${hotReloadScript}</div>` : ''}
|
|
66
|
+
</body>
|
|
67
|
+
</html>`;
|
|
68
|
+
}
|
|
69
|
+
function ensureVueComponent(existingComponent, componentPath) {
|
|
70
|
+
let component = existingComponent;
|
|
71
|
+
if (!component && componentPath) {
|
|
72
|
+
try {
|
|
73
|
+
const module = require(componentPath);
|
|
74
|
+
component = module.default || module;
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (!component)
|
|
81
|
+
return null;
|
|
82
|
+
if (typeof component === 'object' && !component.render && !component.ssrRender && componentPath && componentPath.endsWith('.vue')) {
|
|
83
|
+
try {
|
|
84
|
+
const sfc = require('vue/compiler-sfc');
|
|
85
|
+
const esbuild = require('esbuild');
|
|
86
|
+
const source = fs_1.default.readFileSync(componentPath, 'utf8');
|
|
87
|
+
const { descriptor } = sfc.parse(source, { filename: componentPath });
|
|
88
|
+
if (descriptor.template) {
|
|
89
|
+
const templateResult = sfc.compileTemplate({
|
|
90
|
+
source: descriptor.template.content,
|
|
91
|
+
filename: componentPath,
|
|
92
|
+
id: componentPath,
|
|
93
|
+
ssr: true
|
|
94
|
+
});
|
|
95
|
+
if (templateResult.code) {
|
|
96
|
+
const transformed = esbuild.transformSync(templateResult.code, { loader: 'js', format: 'cjs', target: 'node16' });
|
|
97
|
+
const mod = { exports: {} };
|
|
98
|
+
const runModule = new Function('module', 'exports', 'require', transformed.code);
|
|
99
|
+
runModule(mod, mod.exports, require);
|
|
100
|
+
if (mod.exports.ssrRender)
|
|
101
|
+
component.ssrRender = mod.exports.ssrRender;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch (e) {
|
|
106
|
+
console.warn(`Failed to compile ${componentPath}:`, e);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return component;
|
|
110
|
+
}
|
|
111
|
+
async function renderVue({ req, res, route, params, allRoutes }) {
|
|
112
|
+
(0, common_ts_1.polyfillBrowserEnv)();
|
|
113
|
+
const { createSSRApp, h } = vue;
|
|
114
|
+
const { renderToString } = vueServerRenderer;
|
|
115
|
+
const { generateMetadata } = route;
|
|
116
|
+
const isProduction = !req.hwebDev;
|
|
117
|
+
const hotReloadManager = req.hotReloadManager;
|
|
118
|
+
let assets = null;
|
|
119
|
+
let metadata = { title: 'Vatts App' };
|
|
120
|
+
let layoutInfo = null;
|
|
121
|
+
try {
|
|
122
|
+
assets = (0, common_ts_1.getBuildAssets)();
|
|
123
|
+
// 1. Loading Screen (Vanilla)
|
|
124
|
+
if (!assets || assets.scripts.length === 0) {
|
|
125
|
+
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
126
|
+
res.end((0, BuildingPage_1.getBuildingScreenHtml)());
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
// 2. Setup (Layout/Metadata)
|
|
130
|
+
layoutInfo = (0, router_ts_1.getLayout)();
|
|
131
|
+
let LayoutComponent = null;
|
|
132
|
+
if (layoutInfo) {
|
|
133
|
+
LayoutComponent = ensureVueComponent(null, path_1.default.resolve(process.cwd(), layoutInfo.componentPath));
|
|
134
|
+
}
|
|
135
|
+
if (layoutInfo?.metadata)
|
|
136
|
+
metadata = { ...metadata, ...layoutInfo.metadata };
|
|
137
|
+
if (generateMetadata) {
|
|
138
|
+
const routeMetadata = await Promise.resolve(generateMetadata(params, req));
|
|
139
|
+
metadata = { ...metadata, ...routeMetadata };
|
|
140
|
+
}
|
|
141
|
+
const results = await Promise.all(allRoutes.map(async (r) => {
|
|
142
|
+
let routeMeta = r.generateMetadata ? await Promise.resolve(r.generateMetadata(params, req)) : {};
|
|
143
|
+
return { pattern: r.pattern, componentPath: r.componentPath, metadata: { ...routeMeta, title: routeMeta.title || layoutInfo?.metadata.title || 'Vatts App' } };
|
|
144
|
+
}));
|
|
145
|
+
const obfuscatedData = (0, common_ts_1.obfuscateData)({ routes: results, initialComponentPath: route.componentPath, initialParams: params });
|
|
146
|
+
const hotReloadScript = !isProduction && hotReloadManager ? hotReloadManager.getClientScript() : '';
|
|
147
|
+
const metaTagsHtml = (0, common_ts_1.generateMetaTags)(metadata);
|
|
148
|
+
const htmlLang = metadata.language || 'pt-BR';
|
|
149
|
+
const stylesHtml = assets.styles.map(s => `<link rel="stylesheet" href="${s}">`).join('\n');
|
|
150
|
+
const scriptsHtml = assets.scripts.map(s => `<script type="module" src="${s}"></script>`).join('\n');
|
|
151
|
+
let PageComponent = ensureVueComponent(route.component, route.componentPath ? path_1.default.resolve(process.cwd(), route.componentPath) : '');
|
|
152
|
+
const RootComponent = {
|
|
153
|
+
setup() {
|
|
154
|
+
return () => {
|
|
155
|
+
const pageNode = PageComponent ? h(PageComponent, { params }) : h('div', 'Page not found');
|
|
156
|
+
return LayoutComponent ? h(LayoutComponent, null, { default: () => pageNode }) : pageNode;
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
const app = createSSRApp(RootComponent);
|
|
161
|
+
const bodyInnerHtml = await renderToString(app);
|
|
162
|
+
res.statusCode = 200;
|
|
163
|
+
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
164
|
+
res.end(buildVueShellDocument({
|
|
165
|
+
lang: htmlLang,
|
|
166
|
+
title: metadata.title || 'Vatts.js',
|
|
167
|
+
metaTagsHtml,
|
|
168
|
+
scriptPreloadsHtml: assets.scripts.map(s => `<link rel="modulepreload" href="${s}">`).join('\n'),
|
|
169
|
+
componentPreloadsHtml: (0, common_ts_1.extractComponentPreloads)(route.componentPath ? path_1.default.resolve(process.cwd(), route.componentPath) : '').join('\n'),
|
|
170
|
+
stylesHtml,
|
|
171
|
+
obfuscatedData,
|
|
172
|
+
scriptsHtml,
|
|
173
|
+
hotReloadScript,
|
|
174
|
+
bodyInnerHtml,
|
|
175
|
+
}));
|
|
176
|
+
}
|
|
177
|
+
catch (err) {
|
|
178
|
+
if (!isProduction)
|
|
179
|
+
console.error("Critical Vue Render Error:", err);
|
|
180
|
+
// Fallback para o ServerError Vanilla
|
|
181
|
+
res.statusCode = 500;
|
|
182
|
+
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
183
|
+
let errorHtml = (0, ServerError_1.getServerErrorHtml)({
|
|
184
|
+
error: err,
|
|
185
|
+
title: 'Critical SSR Render Error',
|
|
186
|
+
requestUrl: (0, common_ts_1.getRequestUrl)(req)
|
|
187
|
+
});
|
|
188
|
+
if (!isProduction && hotReloadManager) {
|
|
189
|
+
errorHtml = errorHtml.replace('</body>', `<div style="display:none">${hotReloadManager.getClientScript()}</div></body>`);
|
|
190
|
+
}
|
|
191
|
+
res.end(errorHtml);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function getBuildingScreenHtml(): string;
|