frontend-hamroun 1.2.24 → 1.2.26
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/README.md +3 -0
- package/dist/index.d.ts +6 -1
- package/package.json +1 -1
- package/templates/fullstack-app/api/hello.js +11 -0
- package/templates/fullstack-app/index.html +13 -0
- package/templates/fullstack-app/package-lock.json +3130 -0
- package/templates/fullstack-app/package.json +8 -19
- package/templates/fullstack-app/server.js +210 -0
- package/templates/fullstack-app/server.ts +70 -31
- package/templates/fullstack-app/src/client.js +20 -0
- package/templates/fullstack-app/src/main.tsx +9 -0
- package/templates/fullstack-app/src/pages/index.tsx +40 -36
- package/templates/fullstack-app/vite.config.js +40 -0
- package/templates/ssr-template/package-lock.json +95 -1161
- package/templates/ssr-template/package.json +6 -4
- package/templates/ssr-template/readme.md +112 -37
- package/templates/ssr-template/server.js +364 -549
- package/templates/ssr-template/server.ts +166 -14
- package/templates/ssr-template/tsconfig.json +2 -3
@@ -1,14 +1,16 @@
|
|
1
1
|
{
|
2
|
-
"name": "
|
3
|
-
"private": true,
|
2
|
+
"name": "ssr-app",
|
4
3
|
"version": "0.1.0",
|
5
4
|
"type": "module",
|
6
5
|
"scripts": {
|
7
6
|
"dev": "node server.js",
|
8
|
-
"start": "node server.js"
|
7
|
+
"start": "node server.js",
|
8
|
+
"build": "echo 'No build step required for this template'"
|
9
9
|
},
|
10
10
|
"dependencies": {
|
11
|
+
"dotenv": "^16.0.3",
|
11
12
|
"express": "^4.18.2",
|
12
|
-
"frontend-hamroun": "latest"
|
13
|
+
"frontend-hamroun": "latest",
|
14
|
+
"node-fetch": "^3.3.1"
|
13
15
|
}
|
14
16
|
}
|
@@ -1,14 +1,6 @@
|
|
1
|
-
# Frontend Hamroun
|
1
|
+
# Frontend Hamroun SSR Template
|
2
2
|
|
3
|
-
This
|
4
|
-
|
5
|
-
## Features
|
6
|
-
|
7
|
-
- **Server-Side Rendering**: Pages rendered on the server for optimal SEO and performance
|
8
|
-
- **Authentication**: JWT-based authentication system with login/logout functionality
|
9
|
-
- **Role-Based Authorization**: Different content for regular users and admins
|
10
|
-
- **Protected API Routes**: Secured endpoints that require authentication
|
11
|
-
- **Database Integration**: Optional connection to MongoDB, MySQL, or PostgreSQL
|
3
|
+
This is a comprehensive server-side rendering (SSR) example using Frontend Hamroun.
|
12
4
|
|
13
5
|
## Getting Started
|
14
6
|
|
@@ -22,42 +14,125 @@ This template demonstrates a comprehensive server-side rendering (SSR) applicati
|
|
22
14
|
npm start
|
23
15
|
```
|
24
16
|
|
25
|
-
3. Open your browser at
|
17
|
+
3. Open your browser at http://localhost:3000
|
18
|
+
|
19
|
+
## Core Features
|
20
|
+
|
21
|
+
This template demonstrates:
|
22
|
+
|
23
|
+
### Server-Side Rendering
|
24
|
+
- Pre-rendering of components on the server
|
25
|
+
- Hydration of server-rendered content on the client
|
26
|
+
- Data fetching during server rendering
|
27
|
+
- AI-powered meta tag generation
|
28
|
+
|
29
|
+
### API Integration
|
30
|
+
- RESTful API endpoints
|
31
|
+
- Dynamic API routing
|
32
|
+
- API middleware for validation and security
|
33
|
+
- File-based API structure
|
34
|
+
|
35
|
+
### Database Integration
|
36
|
+
- MongoDB, MySQL, and PostgreSQL support
|
37
|
+
- ORM-like query interface
|
38
|
+
- Connection pooling
|
39
|
+
- Transaction support
|
40
|
+
|
41
|
+
### Authentication & Authorization
|
42
|
+
- JWT-based authentication
|
43
|
+
- Role-based access control
|
44
|
+
- Password hashing and validation
|
45
|
+
- Token refresh mechanism
|
46
|
+
|
47
|
+
### Performance Optimization
|
48
|
+
- Caching strategies
|
49
|
+
- Response compression
|
50
|
+
- Static asset optimization
|
51
|
+
- Efficient metadata handling
|
52
|
+
|
53
|
+
## Implementation Examples
|
54
|
+
|
55
|
+
### Creating Components
|
56
|
+
|
57
|
+
Use the `jsx` or `createElement` function from 'frontend-hamroun':
|
58
|
+
|
59
|
+
```jsx
|
60
|
+
import { jsx } from 'frontend-hamroun';
|
61
|
+
|
62
|
+
export default function MyComponent(props) {
|
63
|
+
return jsx('div', { className: "container" }, [
|
64
|
+
jsx('h1', {}, "Hello World"),
|
65
|
+
jsx('p', {}, `Props value: ${props.value}`)
|
66
|
+
]);
|
67
|
+
}
|
68
|
+
```
|
69
|
+
|
70
|
+
### Creating API Routes
|
71
|
+
|
72
|
+
Create files in the `api` directory following this pattern:
|
73
|
+
|
74
|
+
```typescript
|
75
|
+
// api/users/index.ts
|
76
|
+
import { Request, Response } from 'express';
|
77
|
+
|
78
|
+
export const get = (req: Request, res: Response) => {
|
79
|
+
res.json({ users: [...] });
|
80
|
+
};
|
81
|
+
|
82
|
+
export const post = (req: Request, res: Response) => {
|
83
|
+
// Create user
|
84
|
+
res.status(201).json({ success: true });
|
85
|
+
};
|
86
|
+
```
|
87
|
+
|
88
|
+
### Database Usage
|
89
|
+
|
90
|
+
```typescript
|
91
|
+
import { Server } from 'frontend-hamroun/server';
|
26
92
|
|
27
|
-
|
93
|
+
const server = new Server({
|
94
|
+
db: {
|
95
|
+
url: process.env.DATABASE_URL,
|
96
|
+
type: 'mongodb' // or 'mysql', 'postgres'
|
97
|
+
}
|
98
|
+
});
|
28
99
|
|
29
|
-
|
100
|
+
// Get typed database instance
|
101
|
+
const db = server.getDatabase();
|
102
|
+
const users = await db.query('SELECT * FROM users'); // For SQL
|
103
|
+
const docs = await db.getMongoDb().collection('users').find().toArray(); // For MongoDB
|
104
|
+
```
|
30
105
|
|
31
|
-
|
32
|
-
- Username: `admin`
|
33
|
-
- Password: `admin123`
|
34
|
-
- Roles: `['admin']`
|
106
|
+
### Authentication
|
35
107
|
|
36
|
-
|
37
|
-
|
38
|
-
- Password: `user123`
|
39
|
-
- Roles: `['user']`
|
108
|
+
```typescript
|
109
|
+
import { AuthService } from 'frontend-hamroun/server';
|
40
110
|
|
41
|
-
|
111
|
+
const auth = new AuthService({
|
112
|
+
secret: process.env.JWT_SECRET,
|
113
|
+
expiresIn: '24h'
|
114
|
+
});
|
42
115
|
|
43
|
-
|
116
|
+
// Protect routes
|
117
|
+
app.get('/api/protected', auth.requireAuth(), (req, res) => {
|
118
|
+
res.json({ message: "Authenticated!" });
|
119
|
+
});
|
44
120
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
121
|
+
// Create user & login
|
122
|
+
const hashedPassword = await auth.hashPassword(password);
|
123
|
+
const token = auth.generateToken(user);
|
124
|
+
```
|
49
125
|
|
50
|
-
|
126
|
+
### Advanced Middleware
|
51
127
|
|
52
|
-
|
53
|
-
|
54
|
-
- **DATABASE_URL** - Database connection string (if using database)
|
128
|
+
```typescript
|
129
|
+
import { rateLimit, requestLogger, errorHandler } from 'frontend-hamroun/server';
|
55
130
|
|
56
|
-
|
131
|
+
app.use(requestLogger);
|
132
|
+
app.use('/api', rateLimit({ windowMs: 15 * 60 * 1000, max: 100 }));
|
133
|
+
app.use(errorHandler);
|
134
|
+
```
|
57
135
|
|
58
|
-
|
136
|
+
## Next Steps
|
59
137
|
|
60
|
-
|
61
|
-
2. Connect to a real database by uncommenting the database configuration
|
62
|
-
3. Add more API routes with different authentication requirements
|
63
|
-
4. Enhance the client-side JavaScript with more interactivity
|
138
|
+
Explore the full API documentation for more advanced features and customization options.
|