@fecommunity/reactpress-server 1.0.3-beta.0 → 1.0.4-beta.0

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/README.md +395 -0
  2. package/package.json +3 -3
package/README.md ADDED
@@ -0,0 +1,395 @@
1
+ # @fecommunity/reactpress-server
2
+
3
+ NestJS-based backend API server for ReactPress - A modern React-based CMS platform.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ # For new projects
9
+ npm install @fecommunity/reactpress-server @fecommunity/reactpress-config
10
+
11
+ # Using yarn
12
+ yarn add @fecommunity/reactpress-server @fecommunity/reactpress-config
13
+
14
+ # Using pnpm in workspace root (add -w flag)
15
+ pnpm add -w @fecommunity/reactpress-server @fecommunity/reactpress-config
16
+
17
+ # Using pnpm in standalone project
18
+ pnpm add @fecommunity/reactpress-server @fecommunity/reactpress-config
19
+ ```
20
+
21
+ ## Features
22
+
23
+ - 🚀 **NestJS Framework** - Built on modern, scalable Node.js framework
24
+ - 🔐 **Authentication & Authorization** - JWT-based auth with role management
25
+ - 📝 **Content Management** - Full CRUD for articles, categories, tags, and comments
26
+ - 🗃️ **Database Integration** - MySQL support with TypeORM
27
+ - 📁 **File Upload** - Local and cloud storage support (Ali OSS)
28
+ - 🌍 **Internationalization** - Multi-language support
29
+ - 📚 **API Documentation** - Auto-generated Swagger docs
30
+ - 🔒 **Security** - Rate limiting, CORS, Helmet integration
31
+
32
+ ## Quick Start
33
+
34
+ ### 1. Initialize Server
35
+
36
+ ```bash
37
+ # Using npx (recommended for first-time use)
38
+ npx @fecommunity/reactpress-server init
39
+
40
+ # Or if installed globally
41
+ reactpress-server init
42
+ ```
43
+
44
+ This will create configuration files and set up your environment.
45
+
46
+ ### 2. Start Development Server
47
+
48
+ ```bash
49
+ # Using npx
50
+ npx @fecommunity/reactpress-server dev
51
+
52
+ # Or if installed globally
53
+ reactpress-server dev
54
+ ```
55
+
56
+ The server will start on `http://localhost:3002` with API documentation at `http://localhost:3002/api`.
57
+
58
+ ### 3. Start Production Server
59
+
60
+ ```bash
61
+ # Using npx
62
+ npx @fecommunity/reactpress-server start
63
+
64
+ # Or if installed globally
65
+ reactpress-server start
66
+ ```
67
+
68
+ ## CLI Commands
69
+
70
+ The package includes a powerful CLI for server management:
71
+
72
+ ### Initialize Project
73
+ ```bash
74
+ # Using npx (recommended)
75
+ npx @fecommunity/reactpress-server init [options]
76
+
77
+ # Or if installed globally
78
+ reactpress-server init [options]
79
+
80
+ Options:
81
+ -p, --port <port> Server port (default: 3002)
82
+ --api-prefix <prefix> API prefix (default: /api)
83
+ --db-host <host> Database host (default: localhost)
84
+ --db-port <port> Database port (default: 3306)
85
+ --db-name <name> Database name (default: reactpress)
86
+ ```
87
+
88
+ ### Development Mode
89
+ ```bash
90
+ # Using npx
91
+ npx @fecommunity/reactpress-server dev [options]
92
+
93
+ # Or if installed globally
94
+ reactpress-server dev [options]
95
+
96
+ Options:
97
+ -p, --port <port> Server port (default: 3002)
98
+ --no-open Don't open browser automatically
99
+ ```
100
+
101
+ ### Production Mode
102
+ ```bash
103
+ # Using npx
104
+ npx @fecommunity/reactpress-server start [options]
105
+
106
+ # Or if installed globally
107
+ reactpress-server start [options]
108
+
109
+ Options:
110
+ -p, --port <port> Server port (default: 3002)
111
+ ```
112
+
113
+ ### Build Project
114
+ ```bash
115
+ # Using npx
116
+ npx @fecommunity/reactpress-server build
117
+
118
+ # Or if installed globally
119
+ reactpress-server build
120
+ ```
121
+
122
+ ## Environment Configuration
123
+
124
+ Create a `.env` file in your project root:
125
+
126
+ ```env
127
+ # Server Configuration
128
+ SERVER_PORT=3002
129
+ SERVER_API_PREFIX=/api
130
+ NODE_ENV=development
131
+
132
+ # Database Configuration
133
+ DB_HOST=localhost
134
+ DB_PORT=3306
135
+ DB_USERNAME=root
136
+ DB_PASSWORD=your_password
137
+ DB_DATABASE=reactpress
138
+
139
+ # JWT Configuration
140
+ JWT_SECRET=your_jwt_secret_key
141
+ JWT_EXPIRES_IN=7d
142
+
143
+ # File Upload (Optional - Ali OSS)
144
+ OSS_ACCESS_KEY_ID=your_access_key_id
145
+ OSS_ACCESS_KEY_SECRET=your_access_key_secret
146
+ OSS_BUCKET=your_bucket_name
147
+ OSS_REGION=your_region
148
+
149
+ # Email Configuration (Optional)
150
+ EMAIL_HOST=smtp.gmail.com
151
+ EMAIL_PORT=587
152
+ EMAIL_USER=your_email@gmail.com
153
+ EMAIL_PASS=your_app_password
154
+ ```
155
+
156
+ ## Programmatic Usage
157
+
158
+ You can also use the server programmatically in your Node.js applications:
159
+
160
+ ```typescript
161
+ import { bootstrap } from '@fecommunity/reactpress-server';
162
+
163
+ async function startServer() {
164
+ const app = await bootstrap({
165
+ port: 3002,
166
+ apiPrefix: '/api',
167
+ cors: true
168
+ });
169
+
170
+ console.log('ReactPress server started successfully!');
171
+ }
172
+
173
+ startServer();
174
+ ```
175
+
176
+ ## API Endpoints
177
+
178
+ The server provides comprehensive REST APIs:
179
+
180
+ ### Authentication
181
+ - `POST /api/auth/login` - User login
182
+ - `POST /api/auth/register` - User registration
183
+ - `GET /api/auth/profile` - Get user profile
184
+
185
+ ### Articles
186
+ - `GET /api/articles` - Get articles (with pagination)
187
+ - `POST /api/articles` - Create article
188
+ - `GET /api/articles/:id` - Get article by ID
189
+ - `PUT /api/articles/:id` - Update article
190
+ - `DELETE /api/articles/:id` - Delete article
191
+
192
+ ### Categories
193
+ - `GET /api/categories` - Get all categories
194
+ - `POST /api/categories` - Create category
195
+ - `PUT /api/categories/:id` - Update category
196
+ - `DELETE /api/categories/:id` - Delete category
197
+
198
+ ### Tags
199
+ - `GET /api/tags` - Get all tags
200
+ - `POST /api/tags` - Create tag
201
+ - `PUT /api/tags/:id` - Update tag
202
+ - `DELETE /api/tags/:id` - Delete tag
203
+
204
+ ### Comments
205
+ - `GET /api/comments` - Get comments
206
+ - `POST /api/comments` - Create comment
207
+ - `PUT /api/comments/:id` - Update comment
208
+ - `DELETE /api/comments/:id` - Delete comment
209
+
210
+ ### File Upload
211
+ - `POST /api/upload/image` - Upload image
212
+ - `POST /api/upload/file` - Upload file
213
+
214
+ ## Database Setup
215
+
216
+ ### MySQL Installation
217
+
218
+ **Ubuntu/Debian:**
219
+ ```bash
220
+ sudo apt update
221
+ sudo apt install mysql-server
222
+ sudo mysql_secure_installation
223
+ ```
224
+
225
+ **macOS:**
226
+ ```bash
227
+ brew install mysql
228
+ brew services start mysql
229
+ ```
230
+
231
+ **Windows:**
232
+ Download and install from [MySQL Official Website](https://dev.mysql.com/downloads/mysql/)
233
+
234
+ ### Database Creation
235
+
236
+ ```sql
237
+ CREATE DATABASE reactpress;
238
+ CREATE USER 'reactpress'@'localhost' IDENTIFIED BY 'your_password';
239
+ GRANT ALL PRIVILEGES ON reactpress.* TO 'reactpress'@'localhost';
240
+ FLUSH PRIVILEGES;
241
+ ```
242
+
243
+ ## Advanced Usage
244
+
245
+ ### Custom Configuration
246
+
247
+ ```typescript
248
+ import { NestFactory } from '@nestjs/core';
249
+ import { AppModule } from '@fecommunity/reactpress-server';
250
+
251
+ async function bootstrap() {
252
+ const app = await NestFactory.create(AppModule);
253
+
254
+ // Custom middleware
255
+ app.use('/custom', customMiddleware);
256
+
257
+ // Custom global filters
258
+ app.useGlobalFilters(new CustomExceptionFilter());
259
+
260
+ await app.listen(3002);
261
+ }
262
+
263
+ bootstrap();
264
+ ```
265
+
266
+ ### Plugin Development
267
+
268
+ ```typescript
269
+ import { Module } from '@nestjs/common';
270
+ import { PluginInterface } from '@fecommunity/reactpress-server';
271
+
272
+ @Module({
273
+ // Your plugin implementation
274
+ })
275
+ export class CustomPlugin implements PluginInterface {
276
+ install() {
277
+ // Plugin installation logic
278
+ }
279
+ }
280
+ ```
281
+
282
+ ## Deployment
283
+
284
+ ### PM2 (Recommended)
285
+
286
+ ```bash
287
+ # Install PM2
288
+ npm install -g pm2
289
+
290
+ # Start with PM2
291
+ npm run pm2
292
+
293
+ # Monitor
294
+ pm2 monitor
295
+ ```
296
+
297
+ ### Docker
298
+
299
+ ```dockerfile
300
+ FROM node:18-alpine
301
+ WORKDIR /app
302
+ COPY package*.json ./
303
+ RUN npm install
304
+ COPY . .
305
+ RUN npm run build
306
+ EXPOSE 3002
307
+ CMD ["npm", "start"]
308
+ ```
309
+
310
+ ### Docker Compose
311
+
312
+ ```yaml
313
+ version: '3.8'
314
+ services:
315
+ reactpress-server:
316
+ build: .
317
+ ports:
318
+ - "3002:3002"
319
+ environment:
320
+ - DB_HOST=mysql
321
+ - DB_USERNAME=root
322
+ - DB_PASSWORD=password
323
+ - DB_DATABASE=reactpress
324
+ depends_on:
325
+ - mysql
326
+
327
+ mysql:
328
+ image: mysql:5.7
329
+ environment:
330
+ - MYSQL_ROOT_PASSWORD=password
331
+ - MYSQL_DATABASE=reactpress
332
+ ports:
333
+ - "3306:3306"
334
+ ```
335
+
336
+ ## Integration with Frontend
337
+
338
+ Use with ReactPress client:
339
+
340
+ ```bash
341
+ # Install both server and client
342
+ npm install @fecommunity/reactpress-server @fecommunity/reactpress-client @fecommunity/reactpress-config
343
+
344
+ # Start server
345
+ npx reactpress-server dev
346
+
347
+ # In another terminal, start client
348
+ npx reactpress-client dev
349
+ ```
350
+
351
+ ## Troubleshooting
352
+
353
+ ### Common Issues
354
+
355
+ 1. **Database Connection Error**
356
+ ```
357
+ Error: connect ECONNREFUSED 127.0.0.1:3306
358
+ ```
359
+ - Ensure MySQL is running
360
+ - Check database credentials in `.env`
361
+
362
+ 2. **Port Already in Use**
363
+ ```
364
+ Error: listen EADDRINUSE :::3002
365
+ ```
366
+ - Change port in `.env` file or use `-p` option
367
+
368
+ 3. **JWT Secret Missing**
369
+ ```
370
+ Error: JWT_SECRET is not defined
371
+ ```
372
+ - Add `JWT_SECRET=your_secret_key` to `.env`
373
+
374
+ ### Debug Mode
375
+
376
+ Start server with debug information:
377
+
378
+ ```bash
379
+ DEBUG=* npx reactpress-server dev
380
+ ```
381
+
382
+ ## Contributing
383
+
384
+ Contributions are welcome! Please feel free to submit a Pull Request.
385
+
386
+ ## License
387
+
388
+ MIT
389
+
390
+ ## Links
391
+
392
+ - [GitHub Repository](https://github.com/fecommunity/reactpress)
393
+ - [Documentation](https://reactpress.surge.sh)
394
+ - [npm Package](https://www.npmjs.com/package/@fecommunity/reactpress-server)
395
+ - [API Documentation](http://localhost:3002/api) (when server is running)
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@fecommunity/reactpress-server",
3
- "version": "1.0.3-beta.0",
3
+ "version": "1.0.4-beta.0",
4
4
  "description": "ReactPress Server - NestJS-based backend API for ReactPress CMS",
5
5
  "author": "fecommunity",
6
6
  "license": "MIT",
7
7
  "main": "dist/main.js",
8
8
  "types": "dist/index.d.ts",
9
9
  "bin": {
10
- "@fecommunity/reactpress-server": "../scripts/reactpress-server.js"
10
+ "@fecommunity/reactpress-server": "./scripts/reactpress-server.js"
11
11
  },
12
12
  "files": [
13
13
  "dist/**/*",
@@ -53,7 +53,7 @@
53
53
  "prepublishOnly": "npm run build"
54
54
  },
55
55
  "dependencies": {
56
- "@fecommunity/reactpress-config": "workspace:^1.0.0",
56
+ "@fecommunity/reactpress-config": "^1.0.6-beta.0",
57
57
  "@nestjs/common": "^6.7.2",
58
58
  "@nestjs/config": "^0.6.3",
59
59
  "@nestjs/core": "^6.7.2",