frontend-hamroun 1.2.20 → 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.
Files changed (2) hide show
  1. package/bin/cli.js +7 -38
  2. package/package.json +2 -6
package/bin/cli.js CHANGED
@@ -459,10 +459,15 @@ async function generateApiRoute(name, directory) {
459
459
  }
460
460
 
461
461
  // Add a server template for Express
462
- const SERVER_TEMPLATE = `import { Server, Database, AuthService } from 'frontend-hamroun/server';
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 {
468
+ // Dynamically import server components
469
+ const { Server, Database, AuthService } = await server.getServer();
470
+
466
471
  // Create and configure the server
467
472
  const app = new Server({
468
473
  port: process.env.PORT ? parseInt(process.env.PORT) : 3000,
@@ -472,43 +477,12 @@ async function startServer() {
472
477
  // Enable CORS
473
478
  enableCors: true,
474
479
  corsOptions: {
475
- origin: process.env.CORS_ORIGIN || '*', // Set to specific domain in production
480
+ origin: process.env.CORS_ORIGIN || '*',
476
481
  methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'],
477
482
  allowedHeaders: ['Content-Type', 'Authorization']
478
- },
479
-
480
- // Uncomment to enable database (choose one)
481
- /*
482
- db: {
483
- // MongoDB
484
- url: process.env.MONGODB_URL || 'mongodb://localhost:27017/my_app',
485
- type: 'mongodb'
486
-
487
- // MySQL
488
- // url: process.env.MYSQL_URL || 'mysql://user:password@localhost:3306/my_db',
489
- // type: 'mysql'
490
-
491
- // PostgreSQL
492
- // url: process.env.POSTGRES_URL || 'postgres://user:password@localhost:5432/my_db',
493
- // type: 'postgres'
494
- },
495
- */
496
-
497
- // Uncomment to enable authentication
498
- /*
499
- auth: {
500
- secret: process.env.JWT_SECRET || 'your-secret-key',
501
- expiresIn: '7d'
502
483
  }
503
- */
504
484
  });
505
485
 
506
- // Connect to database if configured
507
- if (app.getDatabase()) {
508
- await app.getDatabase().connect();
509
- console.log('Connected to database');
510
- }
511
-
512
486
  // Start the server
513
487
  await app.start();
514
488
 
@@ -518,12 +492,7 @@ async function startServer() {
518
492
  // Handle graceful shutdown
519
493
  process.on('SIGINT', async () => {
520
494
  console.log('Shutting down server...');
521
- if (app.getDatabase()) {
522
- await app.getDatabase().disconnect();
523
- console.log('Database connection closed');
524
- }
525
495
  await app.stop();
526
- console.log('Server stopped');
527
496
  process.exit(0);
528
497
  });
529
498
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frontend-hamroun",
3
- "version": "1.2.20",
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
- "default": "./dist/server/index.js"
27
- }
23
+ "./server": "./dist/server/index.js"
28
24
  },
29
25
  "bin": {
30
26
  "frontend-hamroun": "./bin/cli.js",