@fecommunity/reactpress-server 1.0.0-beta.13 → 1.0.0-beta.14

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 CHANGED
@@ -1,13 +1,29 @@
1
1
  # @fecommunity/reactpress-server
2
2
 
3
- ReactPress Server - NestJS-based backend API for ReactPress CMS with WordPress-style 5-minute installation.
3
+ ReactPress Server - NestJS 10 backend API for ReactPress CMS with simple installation.
4
+
5
+ [![NPM Version](https://img.shields.io/npm/v/@fecommunity/reactpress-server.svg)](https://www.npmjs.com/package/@fecommunity/reactpress-server)
6
+ [![License](https://img.shields.io/npm/l/@fecommunity/reactpress-server.svg)](https://github.com/fecommunity/reactpress/blob/master/server/LICENSE)
7
+ [![Node Version](https://img.shields.io/node/v/@fecommunity/reactpress-server.svg)](https://nodejs.org)
8
+ [![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](http://www.typescriptlang.org/)
9
+ [![NestJS](https://img.shields.io/badge/NestJS-10-red)](https://nestjs.com/)
10
+
11
+ ## Overview
12
+
13
+ ReactPress Server is a backend API built with NestJS 10 that powers the ReactPress CMS platform. It provides RESTful APIs for content management, user authentication, media handling, and more. With its simple installation process, it offers a smooth setup experience.
14
+
15
+ The server is built with a modular architecture following NestJS best practices, making it extensible and maintainable. It automatically generates OpenAPI/Swagger documentation that powers the [ReactPress Toolkit](../toolkit).
4
16
 
5
17
  ## Quick Start
6
18
 
7
19
  ### Installation & Setup
8
20
 
9
21
  ```bash
22
+ # Regular startup
10
23
  npx @fecommunity/reactpress-server
24
+
25
+ # PM2 startup for production
26
+ npx @fecommunity/reactpress-server --pm2
11
27
  ```
12
28
 
13
29
  That's it! The command will automatically:
@@ -17,30 +33,38 @@ That's it! The command will automatically:
17
33
  3. **Start the server** immediately after installation
18
34
  4. **Open API documentation** at `http://localhost:3002/api`
19
35
 
20
- ### Features
36
+ ## Features
21
37
 
22
- - 🚀 **Zero-command installation** - No complex CLI parameters needed
23
- - 🌍 **WordPress-style setup** - Familiar 5-minute installation process
24
- - 🔧 **Auto-configuration** - Generates `.env` files automatically
25
- - 🔌 **Database auto-setup** - Creates MySQL database if it doesn't exist
26
- - 🎯 **Seamless flow** - From installation to running server in minutes
27
- - 📖 **Auto-documentation** - Swagger API docs available immediately
38
+ - 🚀 **Simple Installation** - No complex CLI parameters needed
39
+ - 🔧 **Auto-Configuration** - Generates `.env` files automatically
40
+ - 🔌 **Database Setup** - Creates MySQL database with migrations
41
+ - 🎯 **Seamless Flow** - From installation to running server
42
+ - 📖 **Auto-Documentation** - Swagger API docs available immediately
43
+ - ⚡ **PM2 Support** - Optional PM2 process management
44
+ - 🔐 **Security** - JWT with refresh token rotation, rate limiting
45
+ - 🛡️ **Protection** - Helmet.js, CSRF protection, input validation
46
+ - 📱 **Responsive APIs** - Mobile-friendly RESTful endpoints
47
+ - 🌐 **Globalization** - Multi-language support
48
+ - 📊 **Analytics Tracking** - Built-in view and visitor analytics
49
+ - 🔄 **Data Synchronization** - Scheduled tasks and webhook support
28
50
 
29
- ### Requirements
51
+ ## Requirements
30
52
 
31
- - Node.js >= 16.5.0
32
- - MySQL 5.7+ or 8.0+
53
+ - Node.js >= 18.20.4
54
+ - MySQL 8.0+ or PostgreSQL 13+
55
+ - npm or pnpm package manager
33
56
 
34
- ### Usage Scenarios
57
+ ## Usage Scenarios
35
58
 
36
- #### Standalone API Server
59
+ ### Standalone API Server
37
60
  Perfect for:
38
61
  - Headless CMS implementation
39
62
  - Mobile app backend
40
63
  - Microservices architecture
41
64
  - Custom frontend integration
65
+ - Enterprise API gateway
42
66
 
43
- #### Full ReactPress Stack
67
+ ### Full ReactPress Stack
44
68
  Use with ReactPress client for complete CMS solution:
45
69
  ```bash
46
70
  # Start server
@@ -50,29 +74,86 @@ npx @fecommunity/reactpress-server
50
74
  npx @fecommunity/reactpress-client
51
75
  ```
52
76
 
53
- ### Configuration
77
+ ## API Modules
78
+
79
+ ReactPress Server provides comprehensive API modules:
80
+
81
+ - **Article Management** - Create, read, update, delete articles with versioning
82
+ - **User Authentication** - Registration, login, password management, 2FA
83
+ - **Comment System** - Comment moderation and management with spam detection
84
+ - **Media Management** - File upload and management (local/S3/Cloudinary)
85
+ - **Category & Tag** - Content organization systems with hierarchy
86
+ - **Page Management** - Custom page creation with templates
87
+ - **Settings** - System configuration management with environment overrides
88
+ - **SMTP** - Email sending capabilities with template system
89
+ - **Search** - Full-text search functionality with Elasticsearch integration
90
+ - **Analytics** - Visitor and view tracking with export capabilities
91
+ - **Webhooks** - Event-driven integrations with external services
92
+ - **Scheduled Tasks** - Cron jobs for automated operations
93
+
94
+ ## PM2 Support
95
+
96
+ ReactPress server supports PM2 process management for production deployments:
97
+
98
+ ```bash
99
+ # Start with PM2
100
+ npx @fecommunity/reactpress-server --pm2
101
+ ```
102
+
103
+ PM2 features:
104
+ - Automatic process restart on crash
105
+ - Memory monitoring
106
+ - Log management with rotation
107
+ - Process management
108
+ - Health checks
109
+
110
+ ## Configuration
54
111
 
55
112
  The installation wizard will create a `.env` file with:
56
113
 
57
114
  ```env
58
- DB_HOST=127.0.0.1
115
+ # Database Configuration (Production)
116
+ DB_HOST=prod-db.cluster-xyz.amazonaws.com
59
117
  DB_PORT=3306
60
- DB_USER=your_username
61
- DB_PASSWD=your_password
62
- DB_DATABASE=reactpress
63
- CLIENT_SITE_URL=http://localhost:3001
64
- SERVER_SITE_URL=http://localhost:3002
118
+ DB_USER=reactpress_user
119
+ DB_PASSWD=secure_password_here
120
+ DB_DATABASE=reactpress_prod
121
+ DB_SSL=true
122
+
123
+ # Site URLs (Production)
124
+ CLIENT_SITE_URL=https://yourdomain.com
125
+ SERVER_SITE_URL=https://api.yourdomain.com
126
+
127
+ # Security Settings (Production)
128
+ JWT_SECRET=your-very-secure-jwt-secret-here
129
+ JWT_EXPIRES_IN=24h
130
+ JWT_REFRESH_EXPIRES_IN=7d
131
+
132
+ # SMTP Configuration (Production)
133
+ SMTP_HOST=email-smtp.us-east-1.amazonaws.com
134
+ SMTP_PORT=587
135
+ SMTP_USER=your_smtp_username
136
+ SMTP_PASS=your_smtp_password
137
+ SMTP_FROM=noreply@yourdomain.com
138
+
139
+ # Cloud Storage (Optional)
140
+ S3_ACCESS_KEY_ID=your_aws_access_key
141
+ S3_SECRET_ACCESS_KEY=your_aws_secret_key
142
+ S3_BUCKET_NAME=your_bucket_name
143
+ S3_REGION=us-east-1
65
144
  ```
66
145
 
67
- ### API Documentation
146
+ ## API Documentation
68
147
 
69
148
  Once running, visit `http://localhost:3002/api` for:
70
149
  - Interactive Swagger documentation
71
150
  - API endpoint explorer
72
151
  - Authentication examples
73
152
  - Response schemas
153
+ - Request/response validation
154
+ - Code generation for multiple languages
74
155
 
75
- ### Development
156
+ ## Development
76
157
 
77
158
  ```bash
78
159
  # Clone repository
@@ -80,29 +161,203 @@ git clone https://github.com/fecommunity/reactpress.git
80
161
  cd reactpress/server
81
162
 
82
163
  # Install dependencies
83
- npm install
164
+ pnpm install
84
165
 
85
- # Start development server
86
- npm run dev
166
+ # Start development server with hot reload
167
+ pnpm run dev
168
+
169
+ # Start with PM2 (development)
170
+ pnpm run pm2:start
171
+
172
+ # Build for production
173
+ pnpm run build
174
+
175
+ # Run tests
176
+ pnpm run test
177
+
178
+ # Run tests with coverage
179
+ pnpm run test:cov
180
+
181
+ # Run end-to-end tests
182
+ pnpm run test:e2e
183
+ ```
184
+
185
+ ## Project Structure
186
+
187
+ ```
188
+ server/
189
+ ├── src/
190
+ │ ├── modules/ # Feature modules
191
+ │ │ ├── article/ # Article management
192
+ │ │ ├── auth/ # Authentication
193
+ │ │ ├── user/ # User management
194
+ │ │ └── ... # Other modules
195
+ │ ├── common/ # Shared utilities and decorators
196
+ │ ├── filters/ # Exception filters
197
+ │ ├── interceptors/ # Request/response interceptors
198
+ │ ├── guards/ # Authentication guards
199
+ │ ├── pipes/ # Data transformation pipes
200
+ │ ├── logger/ # Logging utilities
201
+ │ └── utils/ # Utility functions
202
+ ├── public/ # Static assets
203
+ │ └── swagger/ # Swagger documentation
204
+ ├── dist/ # Compiled output
205
+ └── bin/ # CLI entry points
87
206
  ```
88
207
 
89
- ### Docker Support
208
+ ## Environment Variables
209
+
210
+ | Variable | Description | Default |
211
+ |----------|-------------|---------|
212
+ | `DB_HOST` | Database host | `127.0.0.1` |
213
+ | `DB_PORT` | Database port | `3306` |
214
+ | `DB_USER` | Database username | - |
215
+ | `DB_PASSWD` | Database password | - |
216
+ | `DB_DATABASE` | Database name | `reactpress` |
217
+ | `SERVER_PORT` | Server port | `3002` |
218
+ | `JWT_SECRET` | JWT secret key | - |
219
+ | `CLIENT_SITE_URL` | Client site URL | `http://localhost:3001` |
220
+ | `SERVER_SITE_URL` | Server site URL | `http://localhost:3002` |
221
+ | `SMTP_HOST` | SMTP server host | - |
222
+ | `SMTP_PORT` | SMTP server port | - |
223
+ | `SMTP_USER` | SMTP username | - |
224
+ | `SMTP_PASS` | SMTP password | - |
225
+
226
+ ## CLI Commands
90
227
 
91
228
  ```bash
92
- # Using Docker
93
- docker run -p 3002:3002 @fecommunity/reactpress-server
229
+ # Show help
230
+ npx @fecommunity/reactpress-server --help
231
+
232
+ # Start server
233
+ npx @fecommunity/reactpress-server
234
+
235
+ # Start with PM2
236
+ npx @fecommunity/reactpress-server --pm2
237
+
238
+ # Specify port
239
+ npx @fecommunity/reactpress-server --port 3002
94
240
 
95
- # Using docker-compose
96
- docker-compose up reactpress-server
241
+ # Enable verbose logging
242
+ npx @fecommunity/reactpress-server --verbose
243
+
244
+ # Run database migrations
245
+ npx @fecommunity/reactpress-server --migrate
246
+
247
+ # Seed database with sample data
248
+ npx @fecommunity/reactpress-server --seed
249
+ ```
250
+
251
+ ## Integration with ReactPress Toolkit
252
+
253
+ The server automatically generates the OpenAPI specification that powers the ReactPress Toolkit:
254
+
255
+ ```typescript
256
+ // The toolkit is automatically generated from this server's API
257
+ import { api, types } from '@fecommunity/reactpress-toolkit';
258
+
259
+ // All API endpoints are strongly typed
260
+ const articles: types.IArticle[] = await api.article.findAll();
97
261
  ```
98
262
 
99
- ### Support
263
+ ## Database Schema
264
+
265
+ ReactPress uses MySQL/PostgreSQL with the following key tables:
266
+ - `users` - User accounts and profiles with 2FA support
267
+ - `articles` - Blog posts and content with versioning
268
+ - `categories` - Content categorization with hierarchy
269
+ - `tags` - Content tagging system
270
+ - `comments` - Reader comments and discussions with moderation
271
+ - `files` - Media file management
272
+ - `settings` - System configuration with environment overrides
273
+ - `views` - Analytics and tracking
274
+ - `webhooks` - Event-driven integrations
275
+ - `scheduled_tasks` - Automated operations
276
+
277
+ ## Security Features
278
+
279
+ - **JWT Authentication** - Secure token-based authentication with refresh rotation
280
+ - **Rate Limiting** - Adaptive throttling to prevent abuse
281
+ - **Input Validation** - Sanitize all user inputs with Zod schema validation
282
+ - **Helmet.js** - Secure HTTP headers
283
+ - **CSRF Protection** - Prevent cross-site request forgery
284
+ - **SQL Injection Prevention** - Through TypeORM parameterized queries
285
+ - **CORS Configuration** - Controlled cross-origin resource sharing
286
+ - **Data Encryption** - At-rest encryption for sensitive data
287
+ - **Audit Logging** - Comprehensive activity tracking
288
+
289
+ ## Performance Optimization
290
+
291
+ - **Database Indexing** - Optimized queries with proper indexing
292
+ - **Connection Pooling** - Efficient database connection management
293
+ - **Caching** - Redis integration for frequently accessed data
294
+ - **Compression** - Gzip compression for API responses
295
+ - **Pagination** - Efficient data retrieval for large datasets
296
+ - **Query Optimization** - TypeORM query builder for complex operations
297
+ - **Background Jobs** - Queue system for long-running tasks
298
+
299
+ ## Testing
300
+
301
+ ```bash
302
+ # Run unit tests
303
+ pnpm run test
304
+
305
+ # Run integration tests
306
+ pnpm run test:integration
307
+
308
+ # Run end-to-end tests
309
+ pnpm run test:e2e
310
+
311
+ # Run tests with coverage
312
+ pnpm run test:cov
313
+
314
+ # Run linting
315
+ pnpm run lint
316
+
317
+ # Run formatting
318
+ pnpm run format
319
+
320
+ # Run type checking
321
+ pnpm run type-check
322
+ ```
323
+
324
+ ## Deployment
325
+
326
+ ### Production Deployment with PM2
327
+
328
+ ```
329
+ # Start server with PM2
330
+ npx @fecommunity/reactpress-server --pm2
331
+
332
+ # Or build and start manually
333
+ pnpm run build
334
+ pnpm run start:prod
335
+ ```
336
+
337
+ ## Monitoring & Logging
338
+
339
+ - **Structured Logging** - JSON-formatted logs for easy parsing
340
+ - **Error Tracking** - Comprehensive error reporting with context
341
+ - **Performance Metrics** - Response time and throughput monitoring
342
+ - **Health Checks** - API endpoint for service status
343
+ - **Alerting** - Basic alerting capabilities
344
+
345
+ ## Support
100
346
 
101
347
  - 📖 [Documentation](https://github.com/fecommunity/reactpress)
102
348
  - 🐛 [Issues](https://github.com/fecommunity/reactpress/issues)
103
349
  - 💬 [Discussions](https://github.com/fecommunity/reactpress/discussions)
350
+ - 📧 [Support](mailto:support@reactpress.dev)
351
+
352
+ ## Contributing
353
+
354
+ 1. Fork the repository
355
+ 2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
356
+ 3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
357
+ 4. Push to the branch (`git push origin feature/AmazingFeature`)
358
+ 5. Open a pull request
104
359
 
105
- ### License
360
+ ## License
106
361
 
107
362
  MIT License - see [LICENSE](LICENSE) file for details.
108
363