frontend-hamroun 1.2.19 → 1.2.20
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 +3 -6
- package/package.json +2 -2
- package/templates/fullstack-app/server.ts +34 -42
package/bin/cli.js
CHANGED
@@ -459,13 +459,10 @@ async function generateApiRoute(name, directory) {
|
|
459
459
|
}
|
460
460
|
|
461
461
|
// Add a server template for Express
|
462
|
-
const SERVER_TEMPLATE = `import {
|
462
|
+
const SERVER_TEMPLATE = `import { Server, Database, AuthService } from 'frontend-hamroun/server';
|
463
463
|
|
464
464
|
async function startServer() {
|
465
465
|
try {
|
466
|
-
// Dynamically import server module
|
467
|
-
const { Server } = await server.getServer();
|
468
|
-
|
469
466
|
// Create and configure the server
|
470
467
|
const app = new Server({
|
471
468
|
port: process.env.PORT ? parseInt(process.env.PORT) : 3000,
|
@@ -480,7 +477,7 @@ async function startServer() {
|
|
480
477
|
allowedHeaders: ['Content-Type', 'Authorization']
|
481
478
|
},
|
482
479
|
|
483
|
-
// Uncomment to enable database
|
480
|
+
// Uncomment to enable database (choose one)
|
484
481
|
/*
|
485
482
|
db: {
|
486
483
|
// MongoDB
|
@@ -517,7 +514,7 @@ async function startServer() {
|
|
517
514
|
|
518
515
|
console.log('Server running at http://localhost:' +
|
519
516
|
(process.env.PORT || 3000));
|
520
|
-
|
517
|
+
|
521
518
|
// Handle graceful shutdown
|
522
519
|
process.on('SIGINT', async () => {
|
523
520
|
console.log('Shutting down server...');
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "frontend-hamroun",
|
3
|
-
"version": "1.2.
|
3
|
+
"version": "1.2.20",
|
4
4
|
"description": "A lightweight full-stack JavaScript framework",
|
5
5
|
"type": "module",
|
6
6
|
"main": "./dist/index.js",
|
@@ -23,7 +23,7 @@
|
|
23
23
|
"./server": {
|
24
24
|
"types": "./dist/server/index.d.ts",
|
25
25
|
"import": "./dist/server/index.js",
|
26
|
-
"
|
26
|
+
"default": "./dist/server/index.js"
|
27
27
|
}
|
28
28
|
},
|
29
29
|
"bin": {
|
@@ -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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
|
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();
|