koa-classic-server 1.2.0 → 2.0.0-beta.2
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 +24 -9
- package/__tests__/benchmark-results-baseline-v1.2.0.txt +354 -0
- package/__tests__/benchmark-results-optimized-v2.0.0.txt +354 -0
- package/__tests__/benchmark.js +239 -0
- package/__tests__/demo-regex-index.js +140 -0
- package/__tests__/index-option.test.js +447 -0
- package/__tests__/performance.test.js +370 -0
- package/__tests__/setup-benchmark.js +178 -0
- package/__tests__/test-regex-quick.js +158 -0
- package/docs/BENCHMARKS.md +317 -0
- package/docs/EXAMPLES_INDEX_OPTION.md +395 -0
- package/docs/INDEX_OPTION_PRIORITY.md +527 -0
- package/docs/OPTIMIZATION_HTTP_CACHING.md +687 -0
- package/docs/PERFORMANCE_ANALYSIS.md +839 -0
- package/docs/PERFORMANCE_COMPARISON.md +388 -0
- package/index.cjs +201 -51
- package/jest.config.js +18 -0
- package/package.json +10 -5
- /package/{customTest → __tests__/customTest}/README.md +0 -0
- /package/{customTest → __tests__/customTest}/loadConfig.util.js +0 -0
- /package/{customTest → __tests__/customTest}/serversToLoad.util.js +0 -0
- /package/{DEBUG_REPORT.md → docs/DEBUG_REPORT.md} +0 -0
- /package/{DOCUMENTATION.md → docs/DOCUMENTATION.md} +0 -0
- /package/{noteExports.md → docs/noteExports.md} +0 -0
package/README.md
CHANGED
|
@@ -80,7 +80,7 @@ const app = new Koa();
|
|
|
80
80
|
|
|
81
81
|
app.use(koaClassicServer(__dirname + '/public', {
|
|
82
82
|
showDirContents: true,
|
|
83
|
-
index: 'index.html'
|
|
83
|
+
index: ['index.html'] // Array format (recommended)
|
|
84
84
|
}));
|
|
85
85
|
|
|
86
86
|
app.listen(3000);
|
|
@@ -151,9 +151,19 @@ const options = {
|
|
|
151
151
|
// Show directory contents (default: true)
|
|
152
152
|
showDirContents: true,
|
|
153
153
|
|
|
154
|
-
// Index file
|
|
155
|
-
//
|
|
156
|
-
|
|
154
|
+
// Index file configuration (default: [])
|
|
155
|
+
// RECOMMENDED: Use array format (string format is deprecated)
|
|
156
|
+
// Formats:
|
|
157
|
+
// - Array of strings: ['index.html', 'index.htm', 'default.html']
|
|
158
|
+
// - Array of RegExp: [/index\.html/i] (case-insensitive)
|
|
159
|
+
// - Mixed array: ['index.html', /INDEX\.HTM/i]
|
|
160
|
+
// Priority: First match wins (array order determines search priority)
|
|
161
|
+
//
|
|
162
|
+
// DEPRECATED: String format 'index.html' still works but will be removed
|
|
163
|
+
// in future versions. Please use array format: ['index.html']
|
|
164
|
+
//
|
|
165
|
+
// See INDEX_OPTION_PRIORITY.md for detailed behavior documentation
|
|
166
|
+
index: ['index.html'],
|
|
157
167
|
|
|
158
168
|
// URL path prefix (default: '')
|
|
159
169
|
// Files will be served under this prefix
|
|
@@ -270,7 +280,13 @@ See [CHANGELOG.md](./CHANGELOG.md) for detailed information.
|
|
|
270
280
|
|
|
271
281
|
## Complete Documentation
|
|
272
282
|
|
|
273
|
-
For complete documentation with all features, examples, troubleshooting, and best practices, see
|
|
283
|
+
For complete documentation with all features, examples, troubleshooting, and best practices, see:
|
|
284
|
+
|
|
285
|
+
- **[DOCUMENTATION.md](./docs/DOCUMENTATION.md)** - Complete API reference and usage guide
|
|
286
|
+
- **[INDEX_OPTION_PRIORITY.md](./docs/INDEX_OPTION_PRIORITY.md)** - Detailed priority behavior for `index` option (string, array, RegExp)
|
|
287
|
+
- **[EXAMPLES_INDEX_OPTION.md](./docs/EXAMPLES_INDEX_OPTION.md)** - 10 practical examples of `index` option with RegExp
|
|
288
|
+
- **[PERFORMANCE_ANALYSIS.md](./docs/PERFORMANCE_ANALYSIS.md)** - Performance optimization analysis
|
|
289
|
+
- **[PERFORMANCE_COMPARISON.md](./docs/PERFORMANCE_COMPARISON.md)** - Before/after performance benchmarks
|
|
274
290
|
|
|
275
291
|
## Contributing
|
|
276
292
|
|
|
@@ -279,9 +295,8 @@ Contributions are welcome! Please feel free to submit a Pull Request.
|
|
|
279
295
|
## Known Limitations
|
|
280
296
|
|
|
281
297
|
- Reserved URLs only work for first-level directories
|
|
282
|
-
- Single index file name (no fallback array)
|
|
283
298
|
|
|
284
|
-
See [DEBUG_REPORT.md](./DEBUG_REPORT.md) for technical details.
|
|
299
|
+
See [DEBUG_REPORT.md](./docs/DEBUG_REPORT.md) for technical details.
|
|
285
300
|
|
|
286
301
|
## License
|
|
287
302
|
|
|
@@ -297,8 +312,8 @@ See [CHANGELOG.md](./CHANGELOG.md)
|
|
|
297
312
|
|
|
298
313
|
## Links
|
|
299
314
|
|
|
300
|
-
- [Full Documentation](./DOCUMENTATION.md)
|
|
301
|
-
- [Debug Report](./DEBUG_REPORT.md)
|
|
315
|
+
- [Full Documentation](./docs/DOCUMENTATION.md)
|
|
316
|
+
- [Debug Report](./docs/DEBUG_REPORT.md)
|
|
302
317
|
- [Changelog](./CHANGELOG.md)
|
|
303
318
|
- [Repository](https://github.com/italopaesano/koa-classic-server)
|
|
304
319
|
- [npm Package](https://www.npmjs.com/package/koa-classic-server)
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
|
|
2
|
+
> koa-classic-server@1.2.0 test:performance
|
|
3
|
+
> jest __tests__/performance.test.js --runInBand
|
|
4
|
+
|
|
5
|
+
console.log
|
|
6
|
+
|
|
7
|
+
📊 Small File (1KB) Benchmark:
|
|
8
|
+
|
|
9
|
+
at Object.log (__tests__/performance.test.js:90:21)
|
|
10
|
+
|
|
11
|
+
console.log
|
|
12
|
+
Average: 2.93ms
|
|
13
|
+
|
|
14
|
+
at Object.log (__tests__/performance.test.js:91:21)
|
|
15
|
+
|
|
16
|
+
console.log
|
|
17
|
+
Median: 2.54ms
|
|
18
|
+
|
|
19
|
+
at Object.log (__tests__/performance.test.js:92:21)
|
|
20
|
+
|
|
21
|
+
console.log
|
|
22
|
+
Min: 1.99ms
|
|
23
|
+
|
|
24
|
+
at Object.log (__tests__/performance.test.js:93:21)
|
|
25
|
+
|
|
26
|
+
console.log
|
|
27
|
+
Max: 26.87ms
|
|
28
|
+
|
|
29
|
+
at Object.log (__tests__/performance.test.js:94:21)
|
|
30
|
+
|
|
31
|
+
console.log
|
|
32
|
+
|
|
33
|
+
📊 Medium File (100KB) Benchmark:
|
|
34
|
+
|
|
35
|
+
at Object.log (__tests__/performance.test.js:109:21)
|
|
36
|
+
|
|
37
|
+
console.log
|
|
38
|
+
Average: 3.59ms
|
|
39
|
+
|
|
40
|
+
at Object.log (__tests__/performance.test.js:110:21)
|
|
41
|
+
|
|
42
|
+
console.log
|
|
43
|
+
Median: 3.51ms
|
|
44
|
+
|
|
45
|
+
at Object.log (__tests__/performance.test.js:111:21)
|
|
46
|
+
|
|
47
|
+
console.log
|
|
48
|
+
Min: 2.46ms
|
|
49
|
+
|
|
50
|
+
at Object.log (__tests__/performance.test.js:112:21)
|
|
51
|
+
|
|
52
|
+
console.log
|
|
53
|
+
Max: 8.36ms
|
|
54
|
+
|
|
55
|
+
at Object.log (__tests__/performance.test.js:113:21)
|
|
56
|
+
|
|
57
|
+
console.log
|
|
58
|
+
|
|
59
|
+
📊 Large File (1MB) Benchmark:
|
|
60
|
+
|
|
61
|
+
at Object.log (__tests__/performance.test.js:128:21)
|
|
62
|
+
|
|
63
|
+
console.log
|
|
64
|
+
Average: 9.03ms
|
|
65
|
+
|
|
66
|
+
at Object.log (__tests__/performance.test.js:129:21)
|
|
67
|
+
|
|
68
|
+
console.log
|
|
69
|
+
Median: 8.35ms
|
|
70
|
+
|
|
71
|
+
at Object.log (__tests__/performance.test.js:130:21)
|
|
72
|
+
|
|
73
|
+
console.log
|
|
74
|
+
Min: 5.46ms
|
|
75
|
+
|
|
76
|
+
at Object.log (__tests__/performance.test.js:131:21)
|
|
77
|
+
|
|
78
|
+
console.log
|
|
79
|
+
Max: 13.81ms
|
|
80
|
+
|
|
81
|
+
at Object.log (__tests__/performance.test.js:132:21)
|
|
82
|
+
|
|
83
|
+
console.log
|
|
84
|
+
|
|
85
|
+
📊 Small Directory (100 files) Benchmark:
|
|
86
|
+
|
|
87
|
+
at Object.log (__tests__/performance.test.js:150:21)
|
|
88
|
+
|
|
89
|
+
console.log
|
|
90
|
+
Average: 2.65ms
|
|
91
|
+
|
|
92
|
+
at Object.log (__tests__/performance.test.js:151:21)
|
|
93
|
+
|
|
94
|
+
console.log
|
|
95
|
+
Median: 2.54ms
|
|
96
|
+
|
|
97
|
+
at Object.log (__tests__/performance.test.js:152:21)
|
|
98
|
+
|
|
99
|
+
console.log
|
|
100
|
+
Min: 2.22ms
|
|
101
|
+
|
|
102
|
+
at Object.log (__tests__/performance.test.js:153:21)
|
|
103
|
+
|
|
104
|
+
console.log
|
|
105
|
+
Max: 4.69ms
|
|
106
|
+
|
|
107
|
+
at Object.log (__tests__/performance.test.js:154:21)
|
|
108
|
+
|
|
109
|
+
console.log
|
|
110
|
+
|
|
111
|
+
📊 Large Directory (1,000 files) Benchmark:
|
|
112
|
+
|
|
113
|
+
at Object.log (__tests__/performance.test.js:168:21)
|
|
114
|
+
|
|
115
|
+
console.log
|
|
116
|
+
Average: 9.23ms
|
|
117
|
+
|
|
118
|
+
at Object.log (__tests__/performance.test.js:169:21)
|
|
119
|
+
|
|
120
|
+
console.log
|
|
121
|
+
Median: 9.14ms
|
|
122
|
+
|
|
123
|
+
at Object.log (__tests__/performance.test.js:170:21)
|
|
124
|
+
|
|
125
|
+
console.log
|
|
126
|
+
Min: 8.26ms
|
|
127
|
+
|
|
128
|
+
at Object.log (__tests__/performance.test.js:171:21)
|
|
129
|
+
|
|
130
|
+
console.log
|
|
131
|
+
Max: 11.64ms
|
|
132
|
+
|
|
133
|
+
at Object.log (__tests__/performance.test.js:172:21)
|
|
134
|
+
|
|
135
|
+
console.log
|
|
136
|
+
⚠️ WARNING: This will be MUCH faster after async optimization
|
|
137
|
+
|
|
138
|
+
at Object.log (__tests__/performance.test.js:175:21)
|
|
139
|
+
|
|
140
|
+
console.log
|
|
141
|
+
|
|
142
|
+
📊 Very Large Directory (10,000 files) Benchmark:
|
|
143
|
+
|
|
144
|
+
at Object.log (__tests__/performance.test.js:189:21)
|
|
145
|
+
|
|
146
|
+
console.log
|
|
147
|
+
Average: 102.37ms
|
|
148
|
+
|
|
149
|
+
at Object.log (__tests__/performance.test.js:190:21)
|
|
150
|
+
|
|
151
|
+
console.log
|
|
152
|
+
Median: 95.13ms
|
|
153
|
+
|
|
154
|
+
at Object.log (__tests__/performance.test.js:191:21)
|
|
155
|
+
|
|
156
|
+
console.log
|
|
157
|
+
Min: 90.91ms
|
|
158
|
+
|
|
159
|
+
at Object.log (__tests__/performance.test.js:192:21)
|
|
160
|
+
|
|
161
|
+
console.log
|
|
162
|
+
Max: 120.85ms
|
|
163
|
+
|
|
164
|
+
at Object.log (__tests__/performance.test.js:193:21)
|
|
165
|
+
|
|
166
|
+
console.log
|
|
167
|
+
⚠️ WARNING: Event loop BLOCKED during this operation!
|
|
168
|
+
|
|
169
|
+
at Object.log (__tests__/performance.test.js:194:21)
|
|
170
|
+
|
|
171
|
+
console.log
|
|
172
|
+
⚠️ Expected to drop to ~30.71ms after optimization
|
|
173
|
+
|
|
174
|
+
at Object.log (__tests__/performance.test.js:195:21)
|
|
175
|
+
|
|
176
|
+
console.log
|
|
177
|
+
|
|
178
|
+
📊 10 Concurrent Small Files:
|
|
179
|
+
|
|
180
|
+
at Object.log (__tests__/performance.test.js:212:21)
|
|
181
|
+
|
|
182
|
+
console.log
|
|
183
|
+
Total time: 15.50ms
|
|
184
|
+
|
|
185
|
+
at Object.log (__tests__/performance.test.js:213:21)
|
|
186
|
+
|
|
187
|
+
console.log
|
|
188
|
+
Avg per request: 1.55ms
|
|
189
|
+
|
|
190
|
+
at Object.log (__tests__/performance.test.js:214:21)
|
|
191
|
+
|
|
192
|
+
console.log
|
|
193
|
+
|
|
194
|
+
📊 5 Concurrent Directory Listings (100 files):
|
|
195
|
+
|
|
196
|
+
at Object.log (__tests__/performance.test.js:231:21)
|
|
197
|
+
|
|
198
|
+
console.log
|
|
199
|
+
Total time: 11.30ms
|
|
200
|
+
|
|
201
|
+
at Object.log (__tests__/performance.test.js:232:21)
|
|
202
|
+
|
|
203
|
+
console.log
|
|
204
|
+
Avg per request: 2.26ms
|
|
205
|
+
|
|
206
|
+
at Object.log (__tests__/performance.test.js:233:21)
|
|
207
|
+
|
|
208
|
+
console.log
|
|
209
|
+
⚠️ With current sync code, these run SEQUENTIALLY
|
|
210
|
+
|
|
211
|
+
at Object.log (__tests__/performance.test.js:234:21)
|
|
212
|
+
|
|
213
|
+
console.log
|
|
214
|
+
⚠️ After async optimization, will run in PARALLEL
|
|
215
|
+
|
|
216
|
+
at Object.log (__tests__/performance.test.js:235:21)
|
|
217
|
+
|
|
218
|
+
console.log
|
|
219
|
+
|
|
220
|
+
📊 404 Not Found Benchmark:
|
|
221
|
+
|
|
222
|
+
at Object.log (__tests__/performance.test.js:252:21)
|
|
223
|
+
|
|
224
|
+
console.log
|
|
225
|
+
Average: 1.26ms
|
|
226
|
+
|
|
227
|
+
at Object.log (__tests__/performance.test.js:253:21)
|
|
228
|
+
|
|
229
|
+
console.log
|
|
230
|
+
Median: 1.24ms
|
|
231
|
+
|
|
232
|
+
at Object.log (__tests__/performance.test.js:254:21)
|
|
233
|
+
|
|
234
|
+
console.log
|
|
235
|
+
Min: 1.05ms
|
|
236
|
+
|
|
237
|
+
at Object.log (__tests__/performance.test.js:255:21)
|
|
238
|
+
|
|
239
|
+
console.log
|
|
240
|
+
Max: 2.17ms
|
|
241
|
+
|
|
242
|
+
at Object.log (__tests__/performance.test.js:256:21)
|
|
243
|
+
|
|
244
|
+
console.log
|
|
245
|
+
|
|
246
|
+
📊 Memory Usage (10,000 files directory):
|
|
247
|
+
|
|
248
|
+
at Object.log (__tests__/performance.test.js:278:21)
|
|
249
|
+
|
|
250
|
+
console.log
|
|
251
|
+
Heap used increase: 1.16 MB
|
|
252
|
+
|
|
253
|
+
at Object.log (__tests__/performance.test.js:279:21)
|
|
254
|
+
|
|
255
|
+
console.log
|
|
256
|
+
External increase: 2.57 MB
|
|
257
|
+
|
|
258
|
+
at Object.log (__tests__/performance.test.js:280:21)
|
|
259
|
+
|
|
260
|
+
console.log
|
|
261
|
+
Response size: 1.29 MB
|
|
262
|
+
|
|
263
|
+
at Object.log (__tests__/performance.test.js:281:21)
|
|
264
|
+
|
|
265
|
+
console.log
|
|
266
|
+
⚠️ Expected to reduce by ~30-40% after optimization
|
|
267
|
+
|
|
268
|
+
at Object.log (__tests__/performance.test.js:282:21)
|
|
269
|
+
|
|
270
|
+
console.log
|
|
271
|
+
|
|
272
|
+
======================================================================
|
|
273
|
+
|
|
274
|
+
at Object.log (__tests__/performance.test.js:289:13)
|
|
275
|
+
|
|
276
|
+
console.log
|
|
277
|
+
📋 BASELINE BENCHMARK SUMMARY
|
|
278
|
+
|
|
279
|
+
at Object.log (__tests__/performance.test.js:290:13)
|
|
280
|
+
|
|
281
|
+
console.log
|
|
282
|
+
======================================================================
|
|
283
|
+
|
|
284
|
+
at Object.log (__tests__/performance.test.js:291:13)
|
|
285
|
+
|
|
286
|
+
console.log
|
|
287
|
+
|
|
288
|
+
These results represent the CURRENT performance (v1.2.0)
|
|
289
|
+
|
|
290
|
+
at Object.log (__tests__/performance.test.js:292:13)
|
|
291
|
+
|
|
292
|
+
console.log
|
|
293
|
+
After implementing optimizations, run this test again to see improvements.
|
|
294
|
+
|
|
295
|
+
at Object.log (__tests__/performance.test.js:293:13)
|
|
296
|
+
|
|
297
|
+
console.log
|
|
298
|
+
Expected improvements after optimization:
|
|
299
|
+
|
|
300
|
+
at Object.log (__tests__/performance.test.js:294:13)
|
|
301
|
+
|
|
302
|
+
console.log
|
|
303
|
+
✓ Small files: 10-20% faster (async operations)
|
|
304
|
+
|
|
305
|
+
at Object.log (__tests__/performance.test.js:295:13)
|
|
306
|
+
|
|
307
|
+
console.log
|
|
308
|
+
✓ Large directories: 50-70% faster (async + array join)
|
|
309
|
+
|
|
310
|
+
at Object.log (__tests__/performance.test.js:296:13)
|
|
311
|
+
|
|
312
|
+
console.log
|
|
313
|
+
✓ Concurrent requests: 5-10x faster (non-blocking event loop)
|
|
314
|
+
|
|
315
|
+
at Object.log (__tests__/performance.test.js:297:13)
|
|
316
|
+
|
|
317
|
+
console.log
|
|
318
|
+
✓ Memory usage: 30-40% reduction (array join vs concatenation)
|
|
319
|
+
|
|
320
|
+
at Object.log (__tests__/performance.test.js:298:13)
|
|
321
|
+
|
|
322
|
+
console.log
|
|
323
|
+
✓ With HTTP caching: 80-95% faster (304 responses)
|
|
324
|
+
|
|
325
|
+
at Object.log (__tests__/performance.test.js:299:13)
|
|
326
|
+
|
|
327
|
+
console.log
|
|
328
|
+
======================================================================
|
|
329
|
+
|
|
330
|
+
at Object.log (__tests__/performance.test.js:300:13)
|
|
331
|
+
|
|
332
|
+
PASS __tests__/performance.test.js
|
|
333
|
+
Performance Benchmarks - BASELINE (v1.2.0)
|
|
334
|
+
File Serving Performance
|
|
335
|
+
✓ Benchmark: Small file (1KB) - 100 iterations (318 ms)
|
|
336
|
+
✓ Benchmark: Medium file (100KB) - 50 iterations (184 ms)
|
|
337
|
+
✓ Benchmark: Large file (1MB) - 20 iterations (183 ms)
|
|
338
|
+
Directory Listing Performance
|
|
339
|
+
✓ Benchmark: Small directory (100 files) - 50 iterations (135 ms)
|
|
340
|
+
✓ Benchmark: Large directory (1,000 files) - 20 iterations (188 ms)
|
|
341
|
+
✓ Benchmark: Very large directory (10,000 files) - 5 iterations (515 ms)
|
|
342
|
+
Concurrent Request Performance
|
|
343
|
+
✓ Benchmark: 10 concurrent small file requests (18 ms)
|
|
344
|
+
✓ Benchmark: 5 concurrent directory listings (100 files each) (14 ms)
|
|
345
|
+
404 Not Found Performance
|
|
346
|
+
✓ Benchmark: Non-existent file - 50 iterations (66 ms)
|
|
347
|
+
Memory Usage (Informational)
|
|
348
|
+
✓ Memory usage during large directory listing (88 ms)
|
|
349
|
+
|
|
350
|
+
Test Suites: 1 passed, 1 total
|
|
351
|
+
Tests: 10 passed, 10 total
|
|
352
|
+
Snapshots: 0 total
|
|
353
|
+
Time: 3.227 s, estimated 4 s
|
|
354
|
+
Ran all test suites matching /__tests__\/performance.test.js/i.
|