@noego/forge 0.0.25 → 0.0.27
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/plugins-cjs/routing/html_render/html_render.js +47 -26
- package/dist/plugins-cjs/routing/html_render/html_render.js.map +1 -1
- package/dist/plugins-es/routing/html_render/html_render.js +47 -26
- package/dist/plugins-es/routing/html_render/html_render.js.map +1 -1
- package/dist/routing/html_render/html_render.js +47 -26
- package/dist/routing/html_render/html_render.js.map +1 -1
- package/dist-ssr/server.cjs +37 -22
- package/dist-ssr/server.cjs.map +1 -1
- package/dist-ssr/server.js +37 -22
- package/dist-ssr/server.js.map +1 -1
- package/package.json +2 -1
package/dist-ssr/server.js
CHANGED
|
@@ -8,6 +8,7 @@ import deepmerge from "deepmerge";
|
|
|
8
8
|
import { pathToFileURL } from "url";
|
|
9
9
|
import Handlebars from "handlebars";
|
|
10
10
|
import fs$1 from "fs/promises";
|
|
11
|
+
import { uneval } from "devalue";
|
|
11
12
|
import yaml from "js-yaml";
|
|
12
13
|
import "clone-deep";
|
|
13
14
|
import join from "url-join";
|
|
@@ -149,22 +150,29 @@ class BaseHTMLRender {
|
|
|
149
150
|
let html = template(data);
|
|
150
151
|
const configJson = process.env.NOEGO_CONFIGURATION;
|
|
151
152
|
if (configJson) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
try {
|
|
154
|
+
const configData = JSON.parse(configJson);
|
|
155
|
+
const safeConfigJson = uneval(configData);
|
|
156
|
+
const configScript = `<script>window.__CONFIGURATION__ = ${safeConfigJson};<\/script>`;
|
|
157
|
+
if (html.includes("</head>")) {
|
|
158
|
+
html = html.replace("</head>", `${configScript}
|
|
155
159
|
</head>`);
|
|
156
|
-
|
|
157
|
-
|
|
160
|
+
} else if (html.includes("<body")) {
|
|
161
|
+
html = html.replace(/(<body[^>]*>)/, `$1
|
|
158
162
|
${configScript}`);
|
|
159
|
-
|
|
160
|
-
|
|
163
|
+
} else {
|
|
164
|
+
html = configScript + "\n" + html;
|
|
165
|
+
}
|
|
166
|
+
} catch (e) {
|
|
167
|
+
console.error("Failed to parse NOEGO_CONFIGURATION:", e);
|
|
161
168
|
}
|
|
162
169
|
}
|
|
163
170
|
html = html.replace(
|
|
164
171
|
/<script\s+type=["']module["']\s+src=["']([^"']+)["'][^>]*><\/script>/gi,
|
|
165
|
-
(
|
|
172
|
+
(_match, src) => {
|
|
173
|
+
const safeSrc = src.replace(/'/g, "\\'");
|
|
166
174
|
return `<script type="module">
|
|
167
|
-
import initApp from '${
|
|
175
|
+
import initApp from '${safeSrc}';
|
|
168
176
|
function initializeApp() {
|
|
169
177
|
if (typeof initApp === 'function' && typeof window !== 'undefined' && window.__CONFIGURATION__) {
|
|
170
178
|
const result = initApp();
|
|
@@ -202,22 +210,29 @@ class LiveHTMLRender {
|
|
|
202
210
|
let html = template(data);
|
|
203
211
|
const configJson = process.env.NOEGO_CONFIGURATION;
|
|
204
212
|
if (configJson) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
213
|
+
try {
|
|
214
|
+
const configData = JSON.parse(configJson);
|
|
215
|
+
const safeConfigJson = uneval(configData);
|
|
216
|
+
const configScript = `<script>window.__CONFIGURATION__ = ${safeConfigJson};<\/script>`;
|
|
217
|
+
if (html.includes("</head>")) {
|
|
218
|
+
html = html.replace("</head>", `${configScript}
|
|
208
219
|
</head>`);
|
|
209
|
-
|
|
210
|
-
|
|
220
|
+
} else if (html.includes("<body")) {
|
|
221
|
+
html = html.replace(/(<body[^>]*>)/, `$1
|
|
211
222
|
${configScript}`);
|
|
212
|
-
|
|
213
|
-
|
|
223
|
+
} else {
|
|
224
|
+
html = configScript + "\n" + html;
|
|
225
|
+
}
|
|
226
|
+
} catch (e) {
|
|
227
|
+
console.error("Failed to parse NOEGO_CONFIGURATION:", e);
|
|
214
228
|
}
|
|
215
229
|
}
|
|
216
230
|
html = html.replace(
|
|
217
231
|
/<script\s+type=["']module["']\s+src=["']([^"']+)["'][^>]*><\/script>/gi,
|
|
218
|
-
(
|
|
232
|
+
(_match, src) => {
|
|
233
|
+
const safeSrc = src.replace(/'/g, "\\'");
|
|
219
234
|
return `<script type="module">
|
|
220
|
-
import initApp from '${
|
|
235
|
+
import initApp from '${safeSrc}';
|
|
221
236
|
function initializeApp() {
|
|
222
237
|
if (typeof initApp === 'function' && typeof window !== 'undefined' && window.__CONFIGURATION__) {
|
|
223
238
|
const result = initApp();
|
|
@@ -1111,20 +1126,20 @@ ${e.stack}</pre>
|
|
|
1111
1126
|
const clientComponentDir = this.isProd ? deriveClientBase(this.componentDir || "") : this.componentDir || "/assets";
|
|
1112
1127
|
const head_routing = `
|
|
1113
1128
|
<script type='text/javascript'>
|
|
1114
|
-
window.__ROUTING__ = ${
|
|
1129
|
+
window.__ROUTING__ = ${uneval(this.clientRoutes)}
|
|
1115
1130
|
<\/script>
|
|
1116
1131
|
|
|
1117
1132
|
<script type='text/javascript'>
|
|
1118
|
-
window.__MANIFEST__ = ${
|
|
1133
|
+
window.__MANIFEST__ = ${uneval(manifest)}
|
|
1119
1134
|
console.log('[MANIFEST INJECTED]', window.__MANIFEST__);
|
|
1120
1135
|
<\/script>
|
|
1121
1136
|
|
|
1122
1137
|
<script type='text/javascript'>
|
|
1123
|
-
window.__INITIAL_DATA__ = ${
|
|
1138
|
+
window.__INITIAL_DATA__ = ${uneval(server_data || {})}
|
|
1124
1139
|
<\/script>
|
|
1125
1140
|
|
|
1126
1141
|
<script type='text/javascript'>
|
|
1127
|
-
window.__COMPONENT_DIR__ = ${
|
|
1142
|
+
window.__COMPONENT_DIR__ = ${uneval(clientComponentDir)}
|
|
1128
1143
|
<\/script>
|
|
1129
1144
|
`;
|
|
1130
1145
|
console.log("[SSR DEBUG] About to render HTML with APP length:", (body_render == null ? void 0 : body_render.length) || 0);
|