@noego/forge 0.0.22 → 0.0.24

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.
@@ -146,7 +146,46 @@ class BaseHTMLRender {
146
146
  }
147
147
  async renderHTML(data) {
148
148
  const template = Handlebars.compile(await this.getTemplate());
149
- return template(data);
149
+ let html = template(data);
150
+ const configJson = process.env.NOEGO_CONFIGURATION;
151
+ if (configJson) {
152
+ const configScript = `<script>window.__CONFIGURATION__ = ${configJson};<\/script>`;
153
+ if (html.includes("</head>")) {
154
+ html = html.replace("</head>", `${configScript}
155
+ </head>`);
156
+ } else if (html.includes("<body")) {
157
+ html = html.replace(/(<body[^>]*>)/, `$1
158
+ ${configScript}`);
159
+ } else {
160
+ html = configScript + "\n" + html;
161
+ }
162
+ }
163
+ html = html.replace(
164
+ /<script\s+type=["']module["']\s+src=["']([^"']+)["'][^>]*><\/script>/gi,
165
+ (match, src) => {
166
+ return `<script type="module">
167
+ import initApp from '${src}';
168
+ function initializeApp() {
169
+ if (typeof initApp === 'function' && typeof window !== 'undefined' && window.__CONFIGURATION__) {
170
+ const result = initApp();
171
+ if (result instanceof Promise) {
172
+ result.catch(err => console.error('Failed to initialize app:', err));
173
+ }
174
+ } else {
175
+ console.warn('App initialization skipped: initApp or window.__CONFIGURATION__ not available');
176
+ }
177
+ }
178
+ // Wait for DOM to be ready
179
+ if (document.readyState === 'loading') {
180
+ document.addEventListener('DOMContentLoaded', initializeApp);
181
+ } else {
182
+ // DOM already loaded
183
+ initializeApp();
184
+ }
185
+ <\/script>`;
186
+ }
187
+ );
188
+ return html;
150
189
  }
151
190
  }
152
191
  class DefaultHTMLRender extends BaseHTMLRender {
@@ -160,7 +199,46 @@ class LiveHTMLRender {
160
199
  }
161
200
  async renderHTML(data) {
162
201
  const template = Handlebars.compile(await this.getTemplate());
163
- return template(data);
202
+ let html = template(data);
203
+ const configJson = process.env.NOEGO_CONFIGURATION;
204
+ if (configJson) {
205
+ const configScript = `<script>window.__CONFIGURATION__ = ${configJson};<\/script>`;
206
+ if (html.includes("</head>")) {
207
+ html = html.replace("</head>", `${configScript}
208
+ </head>`);
209
+ } else if (html.includes("<body")) {
210
+ html = html.replace(/(<body[^>]*>)/, `$1
211
+ ${configScript}`);
212
+ } else {
213
+ html = configScript + "\n" + html;
214
+ }
215
+ }
216
+ html = html.replace(
217
+ /<script\s+type=["']module["']\s+src=["']([^"']+)["'][^>]*><\/script>/gi,
218
+ (match, src) => {
219
+ return `<script type="module">
220
+ import initApp from '${src}';
221
+ function initializeApp() {
222
+ if (typeof initApp === 'function' && typeof window !== 'undefined' && window.__CONFIGURATION__) {
223
+ const result = initApp();
224
+ if (result instanceof Promise) {
225
+ result.catch(err => console.error('Failed to initialize app:', err));
226
+ }
227
+ } else {
228
+ console.warn('App initialization skipped: initApp or window.__CONFIGURATION__ not available');
229
+ }
230
+ }
231
+ // Wait for DOM to be ready
232
+ if (document.readyState === 'loading') {
233
+ document.addEventListener('DOMContentLoaded', initializeApp);
234
+ } else {
235
+ // DOM already loaded
236
+ initializeApp();
237
+ }
238
+ <\/script>`;
239
+ }
240
+ );
241
+ return html;
164
242
  }
165
243
  async getTemplate() {
166
244
  const file_content = await fs$1.readFile(this.html_path, "utf8");
@@ -348,7 +426,16 @@ class ManifestBuilder {
348
426
  }
349
427
  }
350
428
  async function requires_server(route, loader) {
351
- return await layout_requires_server(route, loader) || await view_requires_server(route, loader);
429
+ const has_middleware = route.middleware && route.middleware.length > 0;
430
+ const has_loaders = await layout_requires_server(route, loader) || await view_requires_server(route, loader);
431
+ const requires_server2 = has_middleware || has_loaders;
432
+ console.log("[MANIFEST]", route.path, {
433
+ has_middleware,
434
+ middleware: route.middleware,
435
+ has_loaders,
436
+ requires_server: requires_server2
437
+ });
438
+ return requires_server2;
352
439
  }
353
440
  async function layout_requires_server(route, loader) {
354
441
  const layout = route.layout;
@@ -922,8 +1009,18 @@ class ExpressServerAdapter extends ServerAdapter {
922
1009
  body: req.body,
923
1010
  context
924
1011
  };
1012
+ console.log("[SERVER] Handling request", req.url, {
1013
+ middleware: route.middleware,
1014
+ accept: req.headers.accept,
1015
+ route_path: route.path,
1016
+ server_api_call
1017
+ });
925
1018
  try {
926
1019
  await this.middleware_adapter.handleMiddleware(req, res, route.middleware || []);
1020
+ console.log("[SERVER] Middleware complete", {
1021
+ headersSent: res.headersSent,
1022
+ statusCode: res.statusCode
1023
+ });
927
1024
  } catch (e) {
928
1025
  console.log("Error in middleware", e);
929
1026
  res.status(500).send(`
@@ -934,6 +1031,10 @@ ${e.stack}</pre>
934
1031
  `);
935
1032
  return;
936
1033
  }
1034
+ if (res.headersSent) {
1035
+ console.log("[SERVER] Headers already sent by middleware, returning early");
1036
+ return;
1037
+ }
937
1038
  let server_data = await this.api_adapter.getApiData(route, request_data);
938
1039
  if (server_api_call) {
939
1040
  res.header("Cache-Control", "no-store, no-cache, must-revalidate, proxy-revalidate").header("Pragma", "no-cache").header("Expires", "0").type("application/json").send(server_data);
@@ -990,6 +1091,7 @@ ${e.stack}</pre>
990
1091
 
991
1092
  <script type='text/javascript'>
992
1093
  window.__MANIFEST__ = ${JSON.stringify(manifest)}
1094
+ console.log('[MANIFEST INJECTED]', window.__MANIFEST__);
993
1095
  <\/script>
994
1096
 
995
1097
  <script type='text/javascript'>