frontend-hamroun 1.2.77 → 1.2.79

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.
Files changed (72) hide show
  1. package/dist/batch/package.json +1 -1
  2. package/dist/client-router/package.json +1 -1
  3. package/dist/component/package.json +1 -1
  4. package/dist/context/package.json +1 -1
  5. package/dist/event-bus/package.json +1 -1
  6. package/dist/forms/package.json +1 -1
  7. package/dist/hooks/package.json +1 -1
  8. package/dist/index.mjs +1 -0
  9. package/dist/jsx-runtime/package.json +1 -1
  10. package/dist/lifecycle-events/package.json +1 -1
  11. package/dist/package.json +1 -1
  12. package/dist/render-component/package.json +1 -1
  13. package/dist/renderer/package.json +1 -1
  14. package/dist/router/package.json +1 -1
  15. package/dist/server/package.json +1 -1
  16. package/dist/server/src/index.js +24 -23
  17. package/dist/server/src/index.js.map +1 -1
  18. package/dist/server/src/renderComponent.d.ts +8 -9
  19. package/dist/server/src/renderComponent.js +10 -5
  20. package/dist/server/src/renderComponent.js.map +1 -1
  21. package/dist/server/src/server/index.d.ts +23 -34
  22. package/dist/server/src/server/index.js +170 -50
  23. package/dist/server/src/server/index.js.map +1 -1
  24. package/dist/server/src/server/templates.d.ts +2 -0
  25. package/dist/server/src/server/templates.js +9 -5
  26. package/dist/server/src/server/templates.js.map +1 -1
  27. package/dist/server/src/server/utils.d.ts +1 -1
  28. package/dist/server/src/server/utils.js +1 -1
  29. package/dist/server/src/server/utils.js.map +1 -1
  30. package/dist/server/tsconfig.server.tsbuildinfo +1 -1
  31. package/dist/server-renderer/package.json +1 -1
  32. package/dist/store/package.json +1 -1
  33. package/dist/types/package.json +1 -1
  34. package/dist/utils/package.json +1 -1
  35. package/dist/vdom/package.json +1 -1
  36. package/dist/wasm/package.json +1 -1
  37. package/package.json +1 -1
  38. package/templates/complete-app/client.js +58 -0
  39. package/templates/complete-app/package-lock.json +2536 -0
  40. package/templates/complete-app/package.json +8 -31
  41. package/templates/complete-app/pages/about.js +119 -0
  42. package/templates/complete-app/pages/index.js +157 -0
  43. package/templates/complete-app/pages/wasm-demo.js +290 -0
  44. package/templates/complete-app/public/client.js +80 -0
  45. package/templates/complete-app/public/index.html +47 -0
  46. package/templates/complete-app/public/styles.css +446 -212
  47. package/templates/complete-app/readme.md +188 -0
  48. package/templates/complete-app/server.js +417 -0
  49. package/templates/complete-app/server.ts +275 -0
  50. package/templates/complete-app/src/App.tsx +59 -0
  51. package/templates/complete-app/src/client.ts +61 -0
  52. package/templates/complete-app/src/client.tsx +18 -0
  53. package/templates/complete-app/src/pages/index.tsx +51 -0
  54. package/templates/complete-app/src/server.ts +218 -0
  55. package/templates/complete-app/tsconfig.json +22 -0
  56. package/templates/complete-app/tsconfig.server.json +19 -0
  57. package/templates/complete-app/vite.config.js +57 -0
  58. package/templates/complete-app/vite.config.ts +30 -0
  59. package/templates/go/example.go +154 -99
  60. package/templates/complete-app/build.js +0 -284
  61. package/templates/complete-app/src/api/index.js +0 -31
  62. package/templates/complete-app/src/client.js +0 -93
  63. package/templates/complete-app/src/components/App.js +0 -66
  64. package/templates/complete-app/src/components/Footer.js +0 -19
  65. package/templates/complete-app/src/components/Header.js +0 -38
  66. package/templates/complete-app/src/pages/About.js +0 -59
  67. package/templates/complete-app/src/pages/Home.js +0 -54
  68. package/templates/complete-app/src/pages/WasmDemo.js +0 -136
  69. package/templates/complete-app/src/server.js +0 -186
  70. package/templates/complete-app/src/wasm/build.bat +0 -16
  71. package/templates/complete-app/src/wasm/build.sh +0 -16
  72. package/templates/complete-app/src/wasm/example.go +0 -101
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frontend-hamroun/batch",
3
- "version": "1.2.77",
3
+ "version": "1.2.79",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "module": "./index.mjs",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frontend-hamroun/client-router",
3
- "version": "1.2.77",
3
+ "version": "1.2.79",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "module": "./index.mjs",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frontend-hamroun/component",
3
- "version": "1.2.77",
3
+ "version": "1.2.79",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "module": "./index.mjs",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frontend-hamroun/context",
3
- "version": "1.2.77",
3
+ "version": "1.2.79",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "module": "./index.mjs",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frontend-hamroun/event-bus",
3
- "version": "1.2.77",
3
+ "version": "1.2.79",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "module": "./index.mjs",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frontend-hamroun/forms",
3
- "version": "1.2.77",
3
+ "version": "1.2.79",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "module": "./index.mjs",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frontend-hamroun/hooks",
3
- "version": "1.2.77",
3
+ "version": "1.2.79",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "module": "./index.mjs",
package/dist/index.mjs CHANGED
@@ -100,6 +100,7 @@ const K = {
100
100
  Component: F,
101
101
  diff: M,
102
102
  shouldComponentUpdate: S
103
+ // Server functionality is exposed through the server export
103
104
  };
104
105
  export {
105
106
  F as Component,
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frontend-hamroun/jsx-runtime",
3
- "version": "1.2.77",
3
+ "version": "1.2.79",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "module": "./index.mjs",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frontend-hamroun/lifecycle-events",
3
- "version": "1.2.77",
3
+ "version": "1.2.79",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "module": "./index.mjs",
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frontend-hamroun",
3
- "version": "1.2.77",
3
+ "version": "1.2.79",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "module": "./index.mjs",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frontend-hamroun/render-component",
3
- "version": "1.2.77",
3
+ "version": "1.2.79",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "module": "./index.mjs",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frontend-hamroun/renderer",
3
- "version": "1.2.77",
3
+ "version": "1.2.79",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "module": "./index.mjs",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frontend-hamroun/router",
3
- "version": "1.2.77",
3
+ "version": "1.2.79",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "module": "./index.mjs",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frontend-hamroun/server",
3
- "version": "1.2.77",
3
+ "version": "1.2.79",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "module": "./index.mjs",
@@ -43,29 +43,30 @@ export const wasm = {
43
43
  export let isHydrating = false;
44
44
  // Default export for compatibility with some module systems
45
45
  export default {
46
- Fragment: Fragment,
47
- jsx: jsx,
48
- jsxs: jsxs,
49
- createElement: createElement,
50
- render: render,
51
- hydrate: hydrate,
52
- useState: useState,
53
- useEffect: useEffect,
54
- useMemo: useMemo,
55
- useRef: useRef,
56
- useContext: useContext,
57
- useErrorBoundary: useErrorBoundary,
58
- createContext: createContext,
59
- renderToString: renderToString,
60
- batchUpdates: batchUpdates,
61
- server: server,
62
- loadGoWasm: loadGoWasm,
63
- createTypedWasmFunction: createTypedWasmFunction,
64
- goValues: goValues,
65
- wasm: wasm,
66
- Component: Component,
67
- diff: diff,
68
- shouldComponentUpdate: shouldComponentUpdate
46
+ Fragment,
47
+ jsx,
48
+ jsxs,
49
+ createElement,
50
+ render,
51
+ hydrate,
52
+ useState,
53
+ useEffect,
54
+ useMemo,
55
+ useRef,
56
+ useContext,
57
+ useErrorBoundary,
58
+ createContext,
59
+ renderToString,
60
+ batchUpdates,
61
+ server,
62
+ loadGoWasm,
63
+ createTypedWasmFunction,
64
+ goValues,
65
+ wasm,
66
+ Component,
67
+ diff,
68
+ shouldComponentUpdate
69
+ // Server functionality is exposed through the server export
69
70
  };
70
71
  //# sourceMappingURL=index.js.map
71
72
  // This module is compatible with both ESM and CommonJS
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EACL,UAAU,IAAI,cAAc,EAC5B,uBAAuB,IAAI,2BAA2B,EACtD,QAAQ,IAAI,YAAY,EAGzB,MAAM,WAAW,CAAC;AAEnB,6CAA6C;AAC7C,OAAO,EAAE,GAAG,EAAE,IAAI,EAAU,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EACL,QAAQ,EACR,SAAS,EACT,OAAO,EACP,MAAM,EACN,UAAU,EACV,gBAAgB,EACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,YAAY,EAA6B,MAAM,YAAY,CAAC;AACrE,OAAO,EAAE,IAAI,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,6EAA6E;AAC7E,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EACL,GAAG,EACH,IAAI,EACJ,MAAM,EACN,QAAQ,EACR,aAAa,EACd,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,QAAQ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;IACN,UAAU;IACV,gBAAgB;IAChB,aAAa;IACb,cAAc;IACd,YAAY;IACZ,MAAM;IACN,UAAU;IACV,uBAAuB;IACvB,QAAQ;IACR,IAAI;IACJ,SAAS;IACT,IAAI;IACJ,qBAAqB;IACrB,4DAA4D;CAC7D,CAAC"}
@@ -1,14 +1,13 @@
1
1
  /**
2
- * Helper function to render a component to a string
3
- * Used by the server for SSR
2
+ * Result of component rendering
4
3
  */
5
- export declare function renderComponent(Component: any, props?: any): Promise<{
4
+ export interface RenderResult {
6
5
  html: string;
7
6
  success: boolean;
8
- error?: undefined;
9
- } | {
10
- html: string;
11
- success: boolean;
12
- error: unknown;
13
- }>;
7
+ error?: Error;
8
+ }
9
+ /**
10
+ * Renders a component to an HTML string with error handling
11
+ */
12
+ export declare function renderComponent(Component: any, props?: any): Promise<RenderResult>;
14
13
  export default renderComponent;
@@ -1,12 +1,16 @@
1
+ /**
2
+ * Utility for rendering components to strings and hydrating them
3
+ */
1
4
  import { renderToString } from './server-renderer';
2
5
  /**
3
- * Helper function to render a component to a string
4
- * Used by the server for SSR
6
+ * Renders a component to an HTML string with error handling
5
7
  */
6
8
  export async function renderComponent(Component, props = {}) {
7
9
  try {
8
- // Create HTML string from component
9
- const html = renderToString(Component(props));
10
+ // Call the component function with props
11
+ const element = Component(props);
12
+ // Convert the element to an HTML string
13
+ const html = renderToString(element);
10
14
  return {
11
15
  html,
12
16
  success: true
@@ -17,7 +21,8 @@ export async function renderComponent(Component, props = {}) {
17
21
  return {
18
22
  html: `<div class="error">Error rendering component</div>`,
19
23
  success: false,
20
- error
24
+ // Fix the type error by ensuring error is an Error object
25
+ error: error instanceof Error ? error : new Error(String(error))
21
26
  };
22
27
  }
23
28
  }
@@ -1 +1 @@
1
- {"version":3,"file":"renderComponent.js","sourceRoot":"","sources":["../../../src/renderComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD;;;GAGG;AACH,MAAM,CA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AAe,CAAC"}
@@ -1,12 +1,14 @@
1
- import { Express, Request } from 'express';
1
+ import { Express, Request, Response, NextFunction } from 'express';
2
2
  import cors from 'cors';
3
3
  import { SignOptions } from 'jsonwebtoken';
4
4
  import { renderToString } from '../server-renderer.js';
5
5
  import { Database } from './database.js';
6
6
  import { AuthService } from './auth.js';
7
7
  import { ApiRouter } from './api-router.js';
8
- import { safeJsonParse, generateToken, hashString, getPagination, sendSuccess, sendError, validateFields, validateFileUpload, getEnvironmentInfo, isDirectoryEmpty, ensureDirectory, writeJsonFile, readJsonFile } from './utils.js';
9
- import { generateDocument, generateErrorPage, generateLoadingPage } from './templates.js';
8
+ import { rateLimit } from './middleware.js';
9
+ import * as utils from './utils.js';
10
+ import * as templates from './templates.js';
11
+ import { loadGoWasmFromFile } from './wasm.js';
10
12
  export interface ServerConfig {
11
13
  port?: number;
12
14
  apiDir?: string;
@@ -66,11 +68,6 @@ export declare function createDevServer(options?: {
66
68
  export declare function createProductionServer(config: ServerConfig): Server;
67
69
  export declare function getRequestIp(req: Request): string;
68
70
  export declare function parseCookies(req: Request): Record<string, string>;
69
- export { Database } from './database.js';
70
- export { AuthService } from './auth.js';
71
- export { ApiRouter } from './api-router.js';
72
- export { requestLogger, errorHandler, notFoundHandler, rateLimit } from './middleware.js';
73
- export { renderToString };
74
71
  export declare const renderComponent: (Component: any, props?: any) => Promise<{
75
72
  html: string;
76
73
  success: boolean;
@@ -83,15 +80,23 @@ export declare const renderComponent: (Component: any, props?: any) => Promise<{
83
80
  export { initNodeWasm, loadGoWasmFromFile } from './wasm.js';
84
81
  export * from './utils.js';
85
82
  export * from './templates.js';
83
+ export { Database } from './database.js';
84
+ export { AuthService } from './auth.js';
85
+ export { ApiRouter } from './api-router.js';
86
+ export { requestLogger, errorHandler, notFoundHandler, rateLimit } from './middleware.js';
87
+ export { renderToString };
86
88
  declare const _default: {
87
89
  Server: typeof Server;
88
90
  createServer: typeof createServer;
89
91
  createDevServer: typeof createDevServer;
90
92
  createProductionServer: typeof createProductionServer;
91
- Database: typeof Database;
92
- AuthService: typeof AuthService;
93
- ApiRouter: typeof ApiRouter;
94
- renderToString: typeof renderToString;
93
+ rateLimit: typeof rateLimit;
94
+ requestLogger: import("./middleware.js").MiddlewareFunction;
95
+ errorHandler: (err: Error, req: Request, res: Response, next: NextFunction) => void;
96
+ notFoundHandler: (req: Request, res: Response) => void;
97
+ loadGoWasmFromFile: typeof loadGoWasmFromFile;
98
+ templates: typeof templates;
99
+ utils: typeof utils;
95
100
  renderComponent: (Component: any, props?: any) => Promise<{
96
101
  html: string;
97
102
  success: boolean;
@@ -101,27 +106,11 @@ declare const _default: {
101
106
  success: boolean;
102
107
  error: unknown;
103
108
  }>;
104
- templates: {
105
- generateDocument: typeof generateDocument;
106
- generateErrorPage: typeof generateErrorPage;
107
- generateLoadingPage: typeof generateLoadingPage;
108
- };
109
- utils: {
110
- getRequestIp: typeof getRequestIp;
111
- parseCookies: typeof parseCookies;
112
- safeJsonParse: typeof safeJsonParse;
113
- generateToken: typeof generateToken;
114
- hashString: typeof hashString;
115
- getPagination: typeof getPagination;
116
- sendSuccess: typeof sendSuccess;
117
- sendError: typeof sendError;
118
- validateFields: typeof validateFields;
119
- validateFileUpload: typeof validateFileUpload;
120
- getEnvironmentInfo: typeof getEnvironmentInfo;
121
- isDirectoryEmpty: typeof isDirectoryEmpty;
122
- ensureDirectory: typeof ensureDirectory;
123
- writeJsonFile: typeof writeJsonFile;
124
- readJsonFile: typeof readJsonFile;
125
- };
109
+ renderToString: typeof renderToString;
110
+ getRequestIp: typeof getRequestIp;
111
+ parseCookies: typeof parseCookies;
112
+ Database: typeof Database;
113
+ AuthService: typeof AuthService;
114
+ ApiRouter: typeof ApiRouter;
126
115
  };
127
116
  export default _default;
@@ -6,11 +6,35 @@ import { renderToString } from '../server-renderer';
6
6
  import { Database } from './database';
7
7
  import { AuthService } from './auth';
8
8
  import { ApiRouter } from './api-router';
9
- import { requestLogger } from './middleware';
10
- // Import the utility functions that were missing
11
- import { safeJsonParse, generateToken, hashString, getPagination, sendSuccess, sendError, validateFields, validateFileUpload, getEnvironmentInfo, isDirectoryEmpty, ensureDirectory, writeJsonFile, readJsonFile } from './utils';
12
- // Import the HTML template generators
13
- import { generateDocument, generateErrorPage, generateLoadingPage } from './templates';
9
+ import { requestLogger, errorHandler, notFoundHandler, rateLimit } from './middleware';
10
+ // Import the utility functions
11
+ try {
12
+ import * as utils from './utils.js';
13
+ } catch (err) {
14
+ const utils = require('./utils.js');
15
+ };
16
+ try {
17
+ import * as templates from './templates.js';
18
+ } catch (err) {
19
+ const templates = require('./templates.js');
20
+ };
21
+ import { loadGoWasmFromFile } from './wasm';
22
+ // Helper function to get the component name from the file path
23
+ function getComponentName(filePath, pagesDir) {
24
+ try {
25
+ // Get relative path from pages directory
26
+ const relativePath = path.relative(pagesDir, filePath);
27
+ // Remove extension
28
+ const withoutExt = relativePath.replace(/\.[^/.]+$/, '');
29
+ // Replace index with empty for clean paths
30
+ const cleanPath = withoutExt.replace(/\/index$/, '');
31
+ // Convert to module path format
32
+ return `/pages/${cleanPath}`;
33
+ }
34
+ catch (e) {
35
+ return '';
36
+ }
37
+ }
14
38
  export class Server {
15
39
  constructor(config = {}) {
16
40
  Object.defineProperty(this, "app", {
@@ -156,13 +180,124 @@ export class Server {
156
180
  }
157
181
  });
158
182
  }
159
- async renderPage(path) {
160
- // Implementation would find the correct page component and render it
161
- // This is a simplified version
162
- return {
163
- html: `<!DOCTYPE html><html><body><h1>Page: ${path}</h1></body></html>`,
164
- statusCode: 200
165
- };
183
+ async renderPage(routePath) {
184
+ try {
185
+ // Try to find the page component
186
+ const pagesDir = this.config.pagesDir ? path.resolve(process.cwd(), this.config.pagesDir) : '';
187
+ if (!pagesDir || !fs.existsSync(pagesDir)) {
188
+ return {
189
+ html: templates.generateErrorPage(404, 'Pages directory not found'),
190
+ statusCode: 404
191
+ };
192
+ }
193
+ // Normalize the path
194
+ let normalizedPath = routePath;
195
+ if (!normalizedPath.startsWith('/')) {
196
+ normalizedPath = '/' + normalizedPath;
197
+ }
198
+ // Default to index for the root
199
+ if (normalizedPath === '/') {
200
+ normalizedPath = '/index';
201
+ }
202
+ // Try to find a matching page file
203
+ let pagePath = '';
204
+ const possiblePaths = [
205
+ path.join(pagesDir, `${normalizedPath}.js`),
206
+ path.join(pagesDir, `${normalizedPath}.ts`),
207
+ path.join(pagesDir, `${normalizedPath}.jsx`),
208
+ path.join(pagesDir, `${normalizedPath}.tsx`),
209
+ path.join(pagesDir, `${normalizedPath}/index.js`),
210
+ path.join(pagesDir, `${normalizedPath}/index.ts`),
211
+ path.join(pagesDir, `${normalizedPath}/index.jsx`),
212
+ path.join(pagesDir, `${normalizedPath}/index.tsx`)
213
+ ];
214
+ for (const p of possiblePaths) {
215
+ if (fs.existsSync(p)) {
216
+ pagePath = p;
217
+ break;
218
+ }
219
+ }
220
+ // Handle 404 if page not found
221
+ if (!pagePath) {
222
+ return {
223
+ html: templates.generateErrorPage(404, `Page not found: ${normalizedPath}`),
224
+ statusCode: 404
225
+ };
226
+ }
227
+ // Import and render the page component
228
+ try {
229
+ const pageModule = await import(pagePath);
230
+ if (!pageModule || !pageModule.default) {
231
+ throw new Error(`No default export found in ${pagePath}`);
232
+ }
233
+ const PageComponent = pageModule.default;
234
+ const initialProps = {
235
+ // Provide any initial props here
236
+ path: normalizedPath,
237
+ query: {}, // Could be parsed from URL
238
+ api: { serverTime: new Date().toISOString() }
239
+ };
240
+ // Render the component to HTML
241
+ const { html, success, error } = await renderComponent(PageComponent, initialProps);
242
+ if (!success) {
243
+ return {
244
+ html: templates.generateErrorPage(500, 'Failed to render page', error instanceof Error ? error : new Error('Unknown error')),
245
+ statusCode: 500
246
+ };
247
+ }
248
+ // Generate the full HTML document
249
+ let pageTitle = 'My App';
250
+ try {
251
+ // Try to extract title from component if it has a getTitle method
252
+ if (typeof PageComponent.getTitle === 'function') {
253
+ pageTitle = PageComponent.getTitle(initialProps);
254
+ }
255
+ else if (PageComponent.title) {
256
+ pageTitle = PageComponent.title;
257
+ }
258
+ }
259
+ catch (e) {
260
+ // Ignore title errors
261
+ }
262
+ // Parse the component name for hydration
263
+ const componentName = getComponentName(pagePath, pagesDir);
264
+ // Generate full HTML document with our template
265
+ const fullHtml = templates.generateDocument(html, {
266
+ title: pageTitle,
267
+ // Get description from component if available
268
+ description: typeof PageComponent.getDescription === 'function'
269
+ ? PageComponent.getDescription(initialProps)
270
+ : (PageComponent.description || ''),
271
+ // Add scripts for client-side hydration
272
+ scripts: ['/client.js'],
273
+ // Add any custom meta tags
274
+ meta: typeof PageComponent.getMeta === 'function'
275
+ ? PageComponent.getMeta(initialProps)
276
+ : {},
277
+ // Add custom styles
278
+ styles: ['/styles.css'],
279
+ // Add initial data for client-side hydration
280
+ initialData: initialProps,
281
+ // Add component information for hydration
282
+ componentName: componentName
283
+ });
284
+ return { html: fullHtml, statusCode: 200 };
285
+ }
286
+ catch (error) {
287
+ console.error('Error rendering page:', error);
288
+ return {
289
+ html: templates.generateErrorPage(500, 'Error rendering page', error instanceof Error ? error : new Error('Unknown error')),
290
+ statusCode: 500
291
+ };
292
+ }
293
+ }
294
+ catch (error) {
295
+ console.error('Error finding page:', error);
296
+ return {
297
+ html: templates.generateErrorPage(500, 'Server error', error instanceof Error ? error : new Error('Unknown error')),
298
+ statusCode: 500
299
+ };
300
+ }
166
301
  }
167
302
  getExpressApp() {
168
303
  return this.app;
@@ -194,7 +329,6 @@ export class Server {
194
329
  });
195
330
  });
196
331
  }
197
- // Add new utility methods for server management
198
332
  restart() {
199
333
  return this.stop().then(() => this.start());
200
334
  }
@@ -308,15 +442,6 @@ export function parseCookies(req) {
308
442
  }
309
443
  return cookies;
310
444
  }
311
- // Server module main export file
312
- // Export all server components
313
- // Server is already exported above, no need to re-export
314
- export { Database } from './database.js';
315
- export { AuthService } from './auth.js';
316
- export { ApiRouter } from './api-router.js';
317
- export { requestLogger, errorHandler, notFoundHandler, rateLimit } from './middleware.js';
318
- // Export renderToString for convenient SSR
319
- export { renderToString };
320
445
  // Fix the renderComponent function
321
446
  export const renderComponent = async (Component, props = {}) => {
322
447
  try {
@@ -341,41 +466,36 @@ export { initNodeWasm, loadGoWasmFromFile } from './wasm.js';
341
466
  // Import and export server utilities
342
467
  export * from './utils.js';
343
468
  export * from './templates.js';
344
- // Update the default export
469
+ // Export the Database and AuthService classes
470
+ export { Database } from './database.js';
471
+ export { AuthService } from './auth.js';
472
+ export { ApiRouter } from './api-router.js';
473
+ export { requestLogger, errorHandler, notFoundHandler, rateLimit } from './middleware.js';
474
+ // Export renderToString for convenient SSR
475
+ export { renderToString };
476
+ // Ensure the default export includes all required functions
345
477
  export default {
346
478
  Server,
347
479
  createServer,
348
480
  createDevServer,
349
481
  createProductionServer,
350
- Database,
351
- AuthService,
352
- ApiRouter,
353
- renderToString,
354
- renderComponent,
482
+ rateLimit,
483
+ requestLogger,
484
+ errorHandler,
485
+ notFoundHandler,
486
+ loadGoWasmFromFile,
355
487
  // Template utilities
356
- templates: {
357
- generateDocument,
358
- generateErrorPage,
359
- generateLoadingPage
360
- },
488
+ templates,
361
489
  // Server utilities
362
- utils: {
363
- getRequestIp,
364
- parseCookies,
365
- safeJsonParse,
366
- generateToken,
367
- hashString,
368
- getPagination,
369
- sendSuccess,
370
- sendError,
371
- validateFields,
372
- validateFileUpload,
373
- getEnvironmentInfo,
374
- isDirectoryEmpty,
375
- ensureDirectory,
376
- writeJsonFile,
377
- readJsonFile
378
- }
490
+ utils,
491
+ // Additional exports
492
+ renderComponent,
493
+ renderToString,
494
+ getRequestIp,
495
+ parseCookies,
496
+ Database,
497
+ AuthService,
498
+ ApiRouter
379
499
  };
380
500
  //# sourceMappingURL=index.js.map
381
501
  // This module is compatible with both ESM and CommonJS