frontend-hamroun 1.2.19 → 1.2.21

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/bin/cli.js CHANGED
@@ -459,12 +459,14 @@ async function generateApiRoute(name, directory) {
459
459
  }
460
460
 
461
461
  // Add a server template for Express
462
- const SERVER_TEMPLATE = `import { server } from 'frontend-hamroun';
462
+ const SERVER_TEMPLATE = `// Import directly from frontend-hamroun
463
+ // The server module will be dynamically loaded in Node.js environment
464
+ import { server } from 'frontend-hamroun';
463
465
 
464
466
  async function startServer() {
465
467
  try {
466
- // Dynamically import server module
467
- const { Server } = await server.getServer();
468
+ // Dynamically import server components
469
+ const { Server, Database, AuthService } = await server.getServer();
468
470
 
469
471
  // Create and configure the server
470
472
  const app = new Server({
@@ -475,58 +477,22 @@ async function startServer() {
475
477
  // Enable CORS
476
478
  enableCors: true,
477
479
  corsOptions: {
478
- origin: process.env.CORS_ORIGIN || '*', // Set to specific domain in production
480
+ origin: process.env.CORS_ORIGIN || '*',
479
481
  methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'],
480
482
  allowedHeaders: ['Content-Type', 'Authorization']
481
- },
482
-
483
- // Uncomment to enable database
484
- /*
485
- db: {
486
- // MongoDB
487
- url: process.env.MONGODB_URL || 'mongodb://localhost:27017/my_app',
488
- type: 'mongodb'
489
-
490
- // MySQL
491
- // url: process.env.MYSQL_URL || 'mysql://user:password@localhost:3306/my_db',
492
- // type: 'mysql'
493
-
494
- // PostgreSQL
495
- // url: process.env.POSTGRES_URL || 'postgres://user:password@localhost:5432/my_db',
496
- // type: 'postgres'
497
- },
498
- */
499
-
500
- // Uncomment to enable authentication
501
- /*
502
- auth: {
503
- secret: process.env.JWT_SECRET || 'your-secret-key',
504
- expiresIn: '7d'
505
483
  }
506
- */
507
484
  });
508
485
 
509
- // Connect to database if configured
510
- if (app.getDatabase()) {
511
- await app.getDatabase().connect();
512
- console.log('Connected to database');
513
- }
514
-
515
486
  // Start the server
516
487
  await app.start();
517
488
 
518
489
  console.log('Server running at http://localhost:' +
519
490
  (process.env.PORT || 3000));
520
-
491
+
521
492
  // Handle graceful shutdown
522
493
  process.on('SIGINT', async () => {
523
494
  console.log('Shutting down server...');
524
- if (app.getDatabase()) {
525
- await app.getDatabase().disconnect();
526
- console.log('Database connection closed');
527
- }
528
495
  await app.stop();
529
- console.log('Server stopped');
530
496
  process.exit(0);
531
497
  });
532
498
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frontend-hamroun",
3
- "version": "1.2.19",
3
+ "version": "1.2.21",
4
4
  "description": "A lightweight full-stack JavaScript framework",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -20,11 +20,7 @@
20
20
  "require": "./dist/index.js",
21
21
  "default": "./dist/index.js"
22
22
  },
23
- "./server": {
24
- "types": "./dist/server/index.d.ts",
25
- "import": "./dist/server/index.js",
26
- "require": "./dist/server/index.js"
27
- }
23
+ "./server": "./dist/server/index.js"
28
24
  },
29
25
  "bin": {
30
26
  "frontend-hamroun": "./bin/cli.js",
@@ -1,46 +1,38 @@
1
- import { Server } from 'frontend-hamroun';
2
- import path from 'path';
3
- import { fileURLToPath } from 'url';
1
+ import { Server, Database, AuthService } from 'frontend-hamroun/server';
4
2
 
5
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
6
-
7
- const server = new Server({
8
- port: process.env.PORT ? parseInt(process.env.PORT) : 3000,
9
- apiDir: './api',
10
- pagesDir: './src/pages',
11
- staticDir: './public',
12
-
13
- // Uncomment to enable database
14
- /*
15
- db: {
16
- url: process.env.DATABASE_URL || 'mongodb://localhost:27017/my_app',
17
- type: 'mongodb'
18
- },
19
- */
20
-
21
- // Uncomment to enable authentication
22
- /*
23
- auth: {
24
- secret: process.env.JWT_SECRET || 'your-secret-key',
25
- expiresIn: '7d'
3
+ async function startServer() {
4
+ try {
5
+ // Create and configure the server
6
+ const app = new Server({
7
+ port: process.env.PORT ? parseInt(process.env.PORT) : 3000,
8
+ apiDir: './api',
9
+ staticDir: './public',
10
+
11
+ // Enable CORS
12
+ enableCors: true,
13
+ corsOptions: {
14
+ origin: process.env.CORS_ORIGIN || '*',
15
+ methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'],
16
+ allowedHeaders: ['Content-Type', 'Authorization']
17
+ }
18
+ });
19
+
20
+ // Start the server
21
+ await app.start();
22
+
23
+ console.log('Server running at http://localhost:' +
24
+ (process.env.PORT || 3000));
25
+
26
+ // Handle graceful shutdown
27
+ process.on('SIGINT', async () => {
28
+ console.log('Shutting down server...');
29
+ await app.stop();
30
+ process.exit(0);
31
+ });
32
+ } catch (error) {
33
+ console.error('Failed to start server:', error);
34
+ process.exit(1);
26
35
  }
27
- */
28
- });
29
-
30
- // Connect to database if configured
31
- if (server.getDatabase()) {
32
- await server.getDatabase()?.connect();
33
36
  }
34
37
 
35
- // Start the server
36
- await server.start();
37
-
38
- // Handle shutdown gracefully
39
- process.on('SIGINT', async () => {
40
- console.log('Shutting down server...');
41
- await server.stop();
42
- if (server.getDatabase()) {
43
- await server.getDatabase()?.disconnect();
44
- }
45
- process.exit(0);
46
- });
38
+ startServer();