yinzerflow 0.4.4 → 0.5.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.
- package/README.md +31 -26
- package/docs/configuration/configuration.md +815 -0
- package/docs/core/core-concepts.md +801 -0
- package/docs/core/error-handling.md +391 -153
- package/docs/core/logging.md +426 -68
- package/docs/modules/body-parsing.md +561 -0
- package/docs/modules/cors.md +369 -0
- package/docs/modules/index.md +125 -0
- package/docs/modules/ip-security.md +280 -0
- package/docs/modules/rate-limiting.md +795 -0
- package/index.d.ts +278 -76
- package/index.js +18 -18
- package/index.js.map +17 -8
- package/package.json +5 -3
- package/docs/configuration/advanced-configuration-options.md +0 -302
- package/docs/configuration/configuration-patterns.md +0 -500
- package/docs/core/context.md +0 -230
- package/docs/core/examples.md +0 -444
- package/docs/core/request.md +0 -161
- package/docs/core/response.md +0 -212
- package/docs/core/routes.md +0 -720
- package/docs/quick-reference.md +0 -346
- package/docs/security/body-parsing.md +0 -296
- package/docs/security/cors.md +0 -189
- package/docs/security/ip-security.md +0 -234
- package/docs/security/security-overview.md +0 -282
- package/docs/start-here.md +0 -184
|
@@ -1,500 +0,0 @@
|
|
|
1
|
-
# Configuration Patterns
|
|
2
|
-
|
|
3
|
-
YinzerFlow provides flexible configuration options for different deployment environments and use cases. This document contains common configuration patterns and best practices.
|
|
4
|
-
|
|
5
|
-
For security principles and architecture, see [Security Overview](../security/security-overview.md).
|
|
6
|
-
|
|
7
|
-
## Quick Configuration Reference
|
|
8
|
-
|
|
9
|
-
### Minimal Configuration
|
|
10
|
-
```typescript
|
|
11
|
-
import { YinzerFlow } from 'yinzerflow';
|
|
12
|
-
|
|
13
|
-
const app = new YinzerFlow({ port: 3000 });
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
### Basic API Configuration
|
|
17
|
-
```typescript
|
|
18
|
-
const app = new YinzerFlow({
|
|
19
|
-
port: 3000,
|
|
20
|
-
cors: {
|
|
21
|
-
enabled: true,
|
|
22
|
-
origin: ['https://yourdomain.com']
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
### Production Configuration
|
|
28
|
-
```typescript
|
|
29
|
-
const app = new YinzerFlow({
|
|
30
|
-
port: 443,
|
|
31
|
-
cors: {
|
|
32
|
-
enabled: true,
|
|
33
|
-
origin: ['https://yourdomain.com'],
|
|
34
|
-
credentials: true
|
|
35
|
-
},
|
|
36
|
-
bodyParser: {
|
|
37
|
-
json: {
|
|
38
|
-
maxSize: 262144, // 256KB
|
|
39
|
-
allowPrototypeProperties: false
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
ipSecurity: {
|
|
43
|
-
trustedProxies: ['127.0.0.1'],
|
|
44
|
-
detectSpoofing: true
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## Security-First Configurations
|
|
50
|
-
|
|
51
|
-
These configurations prioritize security while maintaining functionality. For detailed security principles, see [Security Overview](../security/security-overview.md).
|
|
52
|
-
|
|
53
|
-
### High-Security Configuration
|
|
54
|
-
For applications requiring maximum security:
|
|
55
|
-
|
|
56
|
-
```typescript
|
|
57
|
-
const highSecurityConfig = {
|
|
58
|
-
port: 443,
|
|
59
|
-
cors: {
|
|
60
|
-
enabled: true,
|
|
61
|
-
origin: ['https://yourdomain.com'], // Specific domain only
|
|
62
|
-
credentials: true,
|
|
63
|
-
methods: ['GET', 'POST'], // Minimal methods
|
|
64
|
-
allowedHeaders: ['Content-Type']
|
|
65
|
-
},
|
|
66
|
-
bodyParser: {
|
|
67
|
-
json: {
|
|
68
|
-
maxSize: 32768, // 32KB only
|
|
69
|
-
maxDepth: 3,
|
|
70
|
-
maxKeys: 50
|
|
71
|
-
},
|
|
72
|
-
fileUploads: {
|
|
73
|
-
maxFileSize: 0, // No file uploads
|
|
74
|
-
maxFiles: 0
|
|
75
|
-
},
|
|
76
|
-
urlEncoded: {
|
|
77
|
-
maxSize: 8192, // 8KB forms only
|
|
78
|
-
maxFields: 20
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
ipSecurity: {
|
|
82
|
-
trustedProxies: [], // No trusted proxies
|
|
83
|
-
allowPrivateIps: false,
|
|
84
|
-
detectSpoofing: true
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
### Public API Configuration
|
|
90
|
-
For public APIs with controlled access:
|
|
91
|
-
|
|
92
|
-
```typescript
|
|
93
|
-
const publicApiConfig = {
|
|
94
|
-
port: 3000,
|
|
95
|
-
cors: {
|
|
96
|
-
enabled: true,
|
|
97
|
-
origin: ['https://api.yourdomain.com'],
|
|
98
|
-
credentials: false, // No credentials for public API
|
|
99
|
-
methods: ['GET', 'POST', 'PUT', 'DELETE'],
|
|
100
|
-
allowedHeaders: ['Content-Type', 'Authorization']
|
|
101
|
-
},
|
|
102
|
-
bodyParser: {
|
|
103
|
-
json: {
|
|
104
|
-
maxSize: 262144, // 256KB
|
|
105
|
-
maxDepth: 10,
|
|
106
|
-
allowPrototypeProperties: false
|
|
107
|
-
},
|
|
108
|
-
fileUploads: {
|
|
109
|
-
maxFileSize: 10485760, // 10MB
|
|
110
|
-
allowedExtensions: ['.jpg', '.png', '.pdf'],
|
|
111
|
-
maxFiles: 5
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
## Environment-Specific Configurations
|
|
118
|
-
|
|
119
|
-
### Development Configuration
|
|
120
|
-
```typescript
|
|
121
|
-
const devConfig = {
|
|
122
|
-
port: 3000,
|
|
123
|
-
cors: {
|
|
124
|
-
enabled: true,
|
|
125
|
-
origin: '*', // Allow all origins in development
|
|
126
|
-
credentials: true
|
|
127
|
-
},
|
|
128
|
-
bodyParser: {
|
|
129
|
-
json: {
|
|
130
|
-
maxSize: 1048576, // 1MB for development
|
|
131
|
-
maxDepth: 20,
|
|
132
|
-
allowPrototypeProperties: false
|
|
133
|
-
},
|
|
134
|
-
fileUploads: {
|
|
135
|
-
maxFileSize: 52428800, // 50MB
|
|
136
|
-
maxFiles: 20,
|
|
137
|
-
allowedExtensions: [] // Allow all for development
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
ipSecurity: {
|
|
141
|
-
allowPrivateIps: true,
|
|
142
|
-
detectSpoofing: false // Disable for development
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
### Staging Configuration
|
|
148
|
-
```typescript
|
|
149
|
-
const stagingConfig = {
|
|
150
|
-
port: 3000,
|
|
151
|
-
cors: {
|
|
152
|
-
enabled: true,
|
|
153
|
-
origin: ['https://staging.yourdomain.com'],
|
|
154
|
-
credentials: true
|
|
155
|
-
},
|
|
156
|
-
bodyParser: {
|
|
157
|
-
json: {
|
|
158
|
-
maxSize: 262144, // 256KB
|
|
159
|
-
maxDepth: 10,
|
|
160
|
-
allowPrototypeProperties: false
|
|
161
|
-
},
|
|
162
|
-
fileUploads: {
|
|
163
|
-
maxFileSize: 10485760, // 10MB
|
|
164
|
-
maxFiles: 10,
|
|
165
|
-
allowedExtensions: ['.jpg', '.png', '.pdf']
|
|
166
|
-
}
|
|
167
|
-
},
|
|
168
|
-
ipSecurity: {
|
|
169
|
-
trustedProxies: ['127.0.0.1'],
|
|
170
|
-
allowPrivateIps: true,
|
|
171
|
-
detectSpoofing: true
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
### Production Configuration
|
|
177
|
-
```typescript
|
|
178
|
-
const productionConfig = {
|
|
179
|
-
port: 443,
|
|
180
|
-
cors: {
|
|
181
|
-
enabled: true,
|
|
182
|
-
origin: ['https://yourdomain.com'],
|
|
183
|
-
credentials: true,
|
|
184
|
-
methods: ['GET', 'POST', 'PUT', 'DELETE'],
|
|
185
|
-
allowedHeaders: ['Content-Type', 'Authorization']
|
|
186
|
-
},
|
|
187
|
-
bodyParser: {
|
|
188
|
-
json: {
|
|
189
|
-
maxSize: 262144, // 256KB
|
|
190
|
-
maxDepth: 10,
|
|
191
|
-
allowPrototypeProperties: false,
|
|
192
|
-
maxKeys: 1000
|
|
193
|
-
},
|
|
194
|
-
fileUploads: {
|
|
195
|
-
maxFileSize: 10485760, // 10MB
|
|
196
|
-
maxFiles: 10,
|
|
197
|
-
allowedExtensions: ['.jpg', '.png', '.pdf'],
|
|
198
|
-
blockedExtensions: ['.exe', '.bat', '.cmd']
|
|
199
|
-
},
|
|
200
|
-
urlEncoded: {
|
|
201
|
-
maxSize: 1048576, // 1MB
|
|
202
|
-
maxFields: 1000
|
|
203
|
-
}
|
|
204
|
-
},
|
|
205
|
-
ipSecurity: {
|
|
206
|
-
trustedProxies: ['127.0.0.1', '192.168.1.10'],
|
|
207
|
-
allowPrivateIps: false,
|
|
208
|
-
headerPreference: ['x-forwarded-for', 'x-real-ip'],
|
|
209
|
-
maxChainLength: 10,
|
|
210
|
-
detectSpoofing: true
|
|
211
|
-
}
|
|
212
|
-
};
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
### High-Security Configuration
|
|
216
|
-
```typescript
|
|
217
|
-
const highSecurityConfig = {
|
|
218
|
-
port: 443,
|
|
219
|
-
cors: {
|
|
220
|
-
enabled: true,
|
|
221
|
-
origin: ['https://yourdomain.com'], // Specific domain only
|
|
222
|
-
credentials: true,
|
|
223
|
-
methods: ['GET', 'POST'], // Minimal methods
|
|
224
|
-
allowedHeaders: ['Content-Type']
|
|
225
|
-
},
|
|
226
|
-
bodyParser: {
|
|
227
|
-
json: {
|
|
228
|
-
maxSize: 32768, // 32KB only
|
|
229
|
-
maxDepth: 3,
|
|
230
|
-
maxKeys: 50
|
|
231
|
-
},
|
|
232
|
-
fileUploads: {
|
|
233
|
-
maxFileSize: 0, // No file uploads
|
|
234
|
-
maxFiles: 0
|
|
235
|
-
},
|
|
236
|
-
urlEncoded: {
|
|
237
|
-
maxSize: 8192, // 8KB forms only
|
|
238
|
-
maxFields: 20
|
|
239
|
-
}
|
|
240
|
-
},
|
|
241
|
-
ipSecurity: {
|
|
242
|
-
trustedProxies: [], // No trusted proxies
|
|
243
|
-
allowPrivateIps: false,
|
|
244
|
-
detectSpoofing: true
|
|
245
|
-
}
|
|
246
|
-
};
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
## Use Case Configurations
|
|
250
|
-
|
|
251
|
-
### File Upload Service Configuration
|
|
252
|
-
```typescript
|
|
253
|
-
const fileUploadConfig = {
|
|
254
|
-
port: 3000,
|
|
255
|
-
cors: {
|
|
256
|
-
enabled: true,
|
|
257
|
-
origin: ['https://upload.yourdomain.com'],
|
|
258
|
-
credentials: true
|
|
259
|
-
},
|
|
260
|
-
bodyParser: {
|
|
261
|
-
json: {
|
|
262
|
-
maxSize: 512000, // 500KB for metadata
|
|
263
|
-
maxDepth: 3,
|
|
264
|
-
allowPrototypeProperties: false
|
|
265
|
-
},
|
|
266
|
-
fileUploads: {
|
|
267
|
-
maxFileSize: 104857600, // 100MB per file
|
|
268
|
-
maxTotalSize: 524288000, // 500MB total
|
|
269
|
-
maxFiles: 20,
|
|
270
|
-
allowedExtensions: ['.jpg', '.jpeg', '.png', '.gif', '.mp4', '.webm', '.pdf'],
|
|
271
|
-
blockedExtensions: [], // Using allowlist instead
|
|
272
|
-
maxFilenameLength: 200
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
};
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
### Microservice Configuration
|
|
279
|
-
```typescript
|
|
280
|
-
const microserviceConfig = {
|
|
281
|
-
port: 3000,
|
|
282
|
-
cors: {
|
|
283
|
-
enabled: false // No CORS for internal services
|
|
284
|
-
},
|
|
285
|
-
bodyParser: {
|
|
286
|
-
json: {
|
|
287
|
-
maxSize: 131072, // 128KB
|
|
288
|
-
maxDepth: 5,
|
|
289
|
-
allowPrototypeProperties: false
|
|
290
|
-
},
|
|
291
|
-
fileUploads: {
|
|
292
|
-
maxFileSize: 0, // No file uploads
|
|
293
|
-
maxFiles: 0
|
|
294
|
-
}
|
|
295
|
-
},
|
|
296
|
-
ipSecurity: {
|
|
297
|
-
trustedProxies: ['127.0.0.1', '10.0.0.0/8'],
|
|
298
|
-
allowPrivateIps: true,
|
|
299
|
-
detectSpoofing: true
|
|
300
|
-
}
|
|
301
|
-
};
|
|
302
|
-
```
|
|
303
|
-
|
|
304
|
-
### Load Balancer Configuration
|
|
305
|
-
```typescript
|
|
306
|
-
const loadBalancerConfig = {
|
|
307
|
-
port: 3000,
|
|
308
|
-
cors: {
|
|
309
|
-
enabled: true,
|
|
310
|
-
origin: ['https://yourdomain.com'],
|
|
311
|
-
credentials: true
|
|
312
|
-
},
|
|
313
|
-
ipSecurity: {
|
|
314
|
-
trustedProxies: ['192.168.1.10', '192.168.1.11'], // Load balancer IPs
|
|
315
|
-
allowPrivateIps: true,
|
|
316
|
-
headerPreference: ['x-forwarded-for', 'x-real-ip'],
|
|
317
|
-
maxChainLength: 5,
|
|
318
|
-
detectSpoofing: true
|
|
319
|
-
}
|
|
320
|
-
};
|
|
321
|
-
```
|
|
322
|
-
|
|
323
|
-
### CDN Configuration
|
|
324
|
-
```typescript
|
|
325
|
-
const cdnConfig = {
|
|
326
|
-
port: 3000,
|
|
327
|
-
cors: {
|
|
328
|
-
enabled: true,
|
|
329
|
-
origin: ['https://yourdomain.com'],
|
|
330
|
-
credentials: true
|
|
331
|
-
},
|
|
332
|
-
ipSecurity: {
|
|
333
|
-
trustedProxies: [
|
|
334
|
-
// Cloudflare IP ranges
|
|
335
|
-
'173.245.48.0/20', '103.21.244.0/22', '103.22.200.0/22'
|
|
336
|
-
],
|
|
337
|
-
headerPreference: ['cf-connecting-ip', 'x-forwarded-for'],
|
|
338
|
-
allowPrivateIps: false // Only real client IPs
|
|
339
|
-
}
|
|
340
|
-
};
|
|
341
|
-
```
|
|
342
|
-
|
|
343
|
-
## Configuration Best Practices
|
|
344
|
-
|
|
345
|
-
### 1. Environment Variables
|
|
346
|
-
Use environment variables for sensitive configuration:
|
|
347
|
-
|
|
348
|
-
```typescript
|
|
349
|
-
const app = new YinzerFlow({
|
|
350
|
-
port: parseInt(process.env.PORT || '3000'),
|
|
351
|
-
cors: {
|
|
352
|
-
enabled: true,
|
|
353
|
-
origin: process.env.ALLOWED_ORIGINS?.split(',') || ['http://localhost:3000']
|
|
354
|
-
},
|
|
355
|
-
bodyParser: {
|
|
356
|
-
json: {
|
|
357
|
-
maxSize: parseInt(process.env.MAX_JSON_SIZE || '262144')
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
});
|
|
361
|
-
```
|
|
362
|
-
|
|
363
|
-
### 2. Configuration Validation
|
|
364
|
-
Validate configuration at startup:
|
|
365
|
-
|
|
366
|
-
```typescript
|
|
367
|
-
const validateConfig = (config: any) => {
|
|
368
|
-
if (!config.port || config.port < 1 || config.port > 65535) {
|
|
369
|
-
throw new Error('Invalid port configuration');
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
if (config.cors?.enabled && !config.cors?.origin) {
|
|
373
|
-
throw new Error('CORS enabled but no origin specified');
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
return config;
|
|
377
|
-
};
|
|
378
|
-
|
|
379
|
-
const config = validateConfig({
|
|
380
|
-
port: 3000,
|
|
381
|
-
cors: { enabled: true, origin: ['https://yourdomain.com'] }
|
|
382
|
-
});
|
|
383
|
-
|
|
384
|
-
const app = new YinzerFlow(config);
|
|
385
|
-
```
|
|
386
|
-
|
|
387
|
-
### 3. Configuration Composition
|
|
388
|
-
Compose configurations from smaller parts:
|
|
389
|
-
|
|
390
|
-
```typescript
|
|
391
|
-
const baseConfig = {
|
|
392
|
-
port: 3000,
|
|
393
|
-
bodyParser: {
|
|
394
|
-
json: {
|
|
395
|
-
allowPrototypeProperties: false
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
};
|
|
399
|
-
|
|
400
|
-
const securityConfig = {
|
|
401
|
-
cors: {
|
|
402
|
-
enabled: true,
|
|
403
|
-
origin: ['https://yourdomain.com']
|
|
404
|
-
},
|
|
405
|
-
ipSecurity: {
|
|
406
|
-
detectSpoofing: true
|
|
407
|
-
}
|
|
408
|
-
};
|
|
409
|
-
|
|
410
|
-
const productionConfig = {
|
|
411
|
-
...baseConfig,
|
|
412
|
-
...securityConfig,
|
|
413
|
-
port: 443
|
|
414
|
-
};
|
|
415
|
-
```
|
|
416
|
-
|
|
417
|
-
### 4. Configuration Testing
|
|
418
|
-
Test your configuration:
|
|
419
|
-
|
|
420
|
-
```typescript
|
|
421
|
-
const testConfig = async (config: any) => {
|
|
422
|
-
const app = new YinzerFlow(config);
|
|
423
|
-
|
|
424
|
-
try {
|
|
425
|
-
await app.listen();
|
|
426
|
-
console.log('✅ Configuration is valid');
|
|
427
|
-
await app.close();
|
|
428
|
-
} catch (error) {
|
|
429
|
-
console.error('❌ Configuration error:', error);
|
|
430
|
-
throw error;
|
|
431
|
-
}
|
|
432
|
-
};
|
|
433
|
-
|
|
434
|
-
await testConfig(productionConfig);
|
|
435
|
-
```
|
|
436
|
-
|
|
437
|
-
## Configuration Reference
|
|
438
|
-
|
|
439
|
-
For detailed configuration options, see:
|
|
440
|
-
|
|
441
|
-
- **[Advanced Configuration Options](./advanced-configuration-options.md)** - Complete configuration reference
|
|
442
|
-
- **[Security Overview](../security/security-overview.md)** - Security configuration patterns
|
|
443
|
-
- **[Body Parsing Security](../security/body-parsing.md)** - Body parser configuration
|
|
444
|
-
- **[CORS Security](../security/cors.md)** - CORS configuration
|
|
445
|
-
- **[IP Security](../security/ip-security.md)** - IP security configuration
|
|
446
|
-
- **[Logging Security](../core/logging.md)** - Logging configuration
|
|
447
|
-
|
|
448
|
-
## Common Issues and Solutions
|
|
449
|
-
|
|
450
|
-
### CORS Errors
|
|
451
|
-
**Problem**: Browser blocks requests due to CORS policy
|
|
452
|
-
**Solution**: Configure CORS with proper origins and credentials
|
|
453
|
-
|
|
454
|
-
```typescript
|
|
455
|
-
cors: {
|
|
456
|
-
enabled: true,
|
|
457
|
-
origin: ['https://yourdomain.com'], // Specific origin
|
|
458
|
-
credentials: true, // If using cookies/auth
|
|
459
|
-
methods: ['GET', 'POST', 'PUT', 'DELETE']
|
|
460
|
-
}
|
|
461
|
-
```
|
|
462
|
-
|
|
463
|
-
### File Upload Failures
|
|
464
|
-
**Problem**: File uploads rejected or too large
|
|
465
|
-
**Solution**: Configure appropriate file upload limits
|
|
466
|
-
|
|
467
|
-
```typescript
|
|
468
|
-
bodyParser: {
|
|
469
|
-
fileUploads: {
|
|
470
|
-
maxFileSize: 10485760, // 10MB per file
|
|
471
|
-
maxFiles: 10,
|
|
472
|
-
allowedExtensions: ['.jpg', '.png', '.pdf']
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
```
|
|
476
|
-
|
|
477
|
-
### IP Address Issues
|
|
478
|
-
**Problem**: Wrong client IP address detected
|
|
479
|
-
**Solution**: Configure trusted proxies for your infrastructure
|
|
480
|
-
|
|
481
|
-
```typescript
|
|
482
|
-
ipSecurity: {
|
|
483
|
-
trustedProxies: ['127.0.0.1', '192.168.1.10'],
|
|
484
|
-
headerPreference: ['x-forwarded-for', 'x-real-ip']
|
|
485
|
-
}
|
|
486
|
-
```
|
|
487
|
-
|
|
488
|
-
### Memory Issues
|
|
489
|
-
**Problem**: Server runs out of memory with large requests
|
|
490
|
-
**Solution**: Reduce body parsing limits
|
|
491
|
-
|
|
492
|
-
```typescript
|
|
493
|
-
bodyParser: {
|
|
494
|
-
json: {
|
|
495
|
-
maxSize: 131072, // 128KB instead of 256KB
|
|
496
|
-
maxDepth: 5, // Shallow nesting
|
|
497
|
-
maxKeys: 100 // Fewer object keys
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
```
|