koa-classic-server 3.0.1 → 3.1.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 (106) hide show
  1. package/README.md +44 -120
  2. package/index.cjs +200 -21
  3. package/package.json +10 -5
  4. package/.github/workflows/npm-publish.yml +0 -98
  5. package/CLAUDE.md +0 -101
  6. package/__tests__/benchmark-results-baseline-v1.2.0.txt +0 -354
  7. package/__tests__/benchmark-results-optimized-v2.0.0.txt +0 -354
  8. package/__tests__/benchmark-results-v3.0.0.txt +0 -372
  9. package/__tests__/benchmark.js +0 -239
  10. package/__tests__/caching-headers.test.js +0 -556
  11. package/__tests__/compression-fixtures/data.json +0 -1
  12. package/__tests__/compression-fixtures/large.txt +0 -1
  13. package/__tests__/compression-fixtures/small.txt +0 -1
  14. package/__tests__/compression.test.js +0 -284
  15. package/__tests__/customTest/README.md +0 -6
  16. package/__tests__/customTest/loadConfig.util.js +0 -41
  17. package/__tests__/customTest/serversToLoad.util.js +0 -93
  18. package/__tests__/demo-regex-index.js +0 -140
  19. package/__tests__/deprecation-warnings.test.js +0 -105
  20. package/__tests__/directory-sorting-links.test.js +0 -135
  21. package/__tests__/dt-unknown.test.js +0 -635
  22. package/__tests__/ejs.test.js +0 -299
  23. package/__tests__/head-method.test.js +0 -160
  24. package/__tests__/hidden-fixtures/.dot-dir/inside.txt +0 -1
  25. package/__tests__/hidden-fixtures/.env +0 -2
  26. package/__tests__/hidden-fixtures/.well-known/acme-challenge.txt +0 -1
  27. package/__tests__/hidden-fixtures/config/secrets/password.txt +0 -1
  28. package/__tests__/hidden-fixtures/data.key +0 -1
  29. package/__tests__/hidden-fixtures/file.secret +0 -1
  30. package/__tests__/hidden-fixtures/index.html +0 -1
  31. package/__tests__/hidden-fixtures/normal.txt +0 -1
  32. package/__tests__/hidden-fixtures/subdir/.env +0 -1
  33. package/__tests__/hidden-fixtures/subdir/regular.txt +0 -1
  34. package/__tests__/hidden-option.test.js +0 -407
  35. package/__tests__/hideExtension.test.js +0 -607
  36. package/__tests__/index-option.test.js +0 -449
  37. package/__tests__/index.test.js +0 -345
  38. package/__tests__/listing.test.js +0 -437
  39. package/__tests__/logger.test.js +0 -232
  40. package/__tests__/performance.test.js +0 -370
  41. package/__tests__/publicWwwTest/cartella/sottocartella/ciao.html +0 -11
  42. package/__tests__/publicWwwTest/cartella/sottocartella/provaEjs/testEjs.ejs +0 -11
  43. package/__tests__/publicWwwTest/cartella vuota con spazi nel nome/file con spazio nel nome .txt +0 -1
  44. package/__tests__/publicWwwTest/cartella vuota con spazi nel nome /file con spazio nel nome .txt +0 -1
  45. package/__tests__/publicWwwTest/ejs-templates/complex.ejs +0 -56
  46. package/__tests__/publicWwwTest/ejs-templates/index.ejs +0 -30
  47. package/__tests__/publicWwwTest/ejs-templates/simple.ejs +0 -13
  48. package/__tests__/publicWwwTest/ejs-templates/with-conditional.ejs +0 -28
  49. package/__tests__/publicWwwTest/ejs-templates/with-escaping.ejs +0 -26
  50. package/__tests__/publicWwwTest/ejs-templates/with-loop.ejs +0 -16
  51. package/__tests__/publicWwwTest/hideext-test/about/index.html +0 -1
  52. package/__tests__/publicWwwTest/hideext-test/about.EJS +0 -1
  53. package/__tests__/publicWwwTest/hideext-test/about.ejs +0 -2
  54. package/__tests__/publicWwwTest/hideext-test/blog/articolo.ejs +0 -2
  55. package/__tests__/publicWwwTest/hideext-test/conflict-test/pagina +0 -1
  56. package/__tests__/publicWwwTest/hideext-test/conflict-test/pagina.ejs +0 -1
  57. package/__tests__/publicWwwTest/hideext-test/file.ejs.bak +0 -1
  58. package/__tests__/publicWwwTest/hideext-test/index.ejs +0 -2
  59. package/__tests__/publicWwwTest/hideext-test/photo.txt +0 -1
  60. package/__tests__/publicWwwTest/hideext-test/sezione/index.ejs +0 -1
  61. package/__tests__/publicWwwTest/hideext-test/style.css +0 -1
  62. package/__tests__/publicWwwTest/ile_vuoto.txt +0 -0
  63. package/__tests__/publicWwwTest/index.html +0 -11
  64. package/__tests__/publicWwwTest/prova file .txt +0 -2
  65. package/__tests__/publicWwwTest/semplicetxt.txt +0 -1
  66. package/__tests__/publicWwwTest/test-page.html +0 -1
  67. package/__tests__/publicWwwTest/test.txt +0 -1
  68. package/__tests__/range-fixtures/sample.txt +0 -1
  69. package/__tests__/range.test.js +0 -223
  70. package/__tests__/security-headers.test.js +0 -165
  71. package/__tests__/security.test.js +0 -322
  72. package/__tests__/server-cache-fixtures/large.txt +0 -1
  73. package/__tests__/server-cache-fixtures/small.txt +0 -1
  74. package/__tests__/server-cache.test.js +0 -594
  75. package/__tests__/setup-benchmark.js +0 -178
  76. package/__tests__/symlink.test.js +0 -441
  77. package/__tests__/template-timeout.test.js +0 -321
  78. package/__tests__/test-regex-quick.js +0 -158
  79. package/__tests__/useOriginalUrl.test.js +0 -213
  80. package/docs/ACTION_PLAN.md +0 -293
  81. package/docs/BENCHMARKS.md +0 -317
  82. package/docs/CHANGELOG.md +0 -906
  83. package/docs/CODE_REVIEW.md +0 -300
  84. package/docs/DEBUG_REPORT.md +0 -593
  85. package/docs/DOCUMENTATION.md +0 -1864
  86. package/docs/EXAMPLES_INDEX_OPTION.md +0 -395
  87. package/docs/FLOW_DIAGRAM.md +0 -954
  88. package/docs/INDEX_OPTION_PRIORITY.md +0 -527
  89. package/docs/OPTIMIZATION_HTTP_CACHING.md +0 -689
  90. package/docs/OPTIMIZATION_ROADMAP_for_V3.md +0 -864
  91. package/docs/PERFORMANCE_ANALYSIS.md +0 -839
  92. package/docs/PERFORMANCE_COMPARISON.md +0 -388
  93. package/docs/noteExports.md +0 -148
  94. package/docs/security_improvement_for_V3.md +0 -421
  95. package/docs/template-engine/TEMPLATE_ENGINE_GUIDE.md +0 -1734
  96. package/docs/template-engine/esempi-incrementali.js +0 -192
  97. package/docs/template-engine/examples/esempio1-nessun-dato.ejs +0 -12
  98. package/docs/template-engine/examples/esempio2-una-variabile.ejs +0 -11
  99. package/docs/template-engine/examples/esempio3-piu-variabili.ejs +0 -15
  100. package/docs/template-engine/examples/esempio4-condizionale.ejs +0 -18
  101. package/docs/template-engine/examples/esempio5-loop.ejs +0 -18
  102. package/docs/template-engine/examples/index-esempi.html +0 -181
  103. package/docs/template-engine/examples/index.html +0 -40
  104. package/docs/template-engine/examples/test.ejs +0 -64
  105. package/eslint.config.mjs +0 -17
  106. package/jest.config.js +0 -18
@@ -1,239 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * HTTP Load Testing Benchmark using autocannon
5
- *
6
- * This script performs realistic load testing to measure:
7
- * - Requests per second
8
- * - Latency (avg, p50, p99)
9
- * - Throughput
10
- *
11
- * Usage:
12
- * node benchmark.js
13
- * node benchmark.js --save baseline.json
14
- *
15
- * Compare before/after:
16
- * node benchmark.js --save before.json
17
- * # ... apply optimizations ...
18
- * node benchmark.js --save after.json --compare before.json
19
- */
20
-
21
- const autocannon = require('autocannon');
22
- const Koa = require('koa');
23
- const koaClassicServer = require('../index.cjs');
24
- const path = require('path');
25
- const fs = require('fs');
26
-
27
- const BENCHMARK_DIR = path.join(__dirname, 'benchmark-data');
28
-
29
- // Check if benchmark data exists
30
- if (!fs.existsSync(BENCHMARK_DIR)) {
31
- console.error('\nāŒ Benchmark data not found!');
32
- console.error('Please run: node scripts/setup-benchmark.js\n');
33
- process.exit(1);
34
- }
35
-
36
- // Parse command line arguments
37
- const args = process.argv.slice(2);
38
- const saveFile = args.includes('--save') ? args[args.indexOf('--save') + 1] : null;
39
- const compareFile = args.includes('--compare') ? args[args.indexOf('--compare') + 1] : null;
40
-
41
- console.log('šŸš€ Starting koa-classic-server benchmark...\n');
42
-
43
- // Start server
44
- const app = new Koa();
45
- app.use(koaClassicServer(BENCHMARK_DIR));
46
- const server = app.listen(0); // Random available port
47
-
48
- const port = server.address().port;
49
- console.log(`Server running on http://localhost:${port}\n`);
50
-
51
- // Define benchmark scenarios
52
- const scenarios = [
53
- {
54
- name: 'Small file (1KB)',
55
- url: `http://localhost:${port}/small-files/file-1.txt`,
56
- duration: 10,
57
- connections: 10
58
- },
59
- {
60
- name: 'Medium file (100KB)',
61
- url: `http://localhost:${port}/medium-files/file-1.txt`,
62
- duration: 10,
63
- connections: 10
64
- },
65
- {
66
- name: 'Large file (1MB)',
67
- url: `http://localhost:${port}/large-files/file-1.txt`,
68
- duration: 10,
69
- connections: 10
70
- },
71
- {
72
- name: 'Directory listing (100 files)',
73
- url: `http://localhost:${port}/small-files/`,
74
- duration: 10,
75
- connections: 10
76
- },
77
- {
78
- name: 'Directory listing (1,000 files)',
79
- url: `http://localhost:${port}/large-directory/`,
80
- duration: 10,
81
- connections: 5
82
- },
83
- {
84
- name: 'HTML file',
85
- url: `http://localhost:${port}/test.html`,
86
- duration: 10,
87
- connections: 10
88
- },
89
- {
90
- name: '404 Not Found',
91
- url: `http://localhost:${port}/does-not-exist.txt`,
92
- duration: 10,
93
- connections: 10
94
- }
95
- ];
96
-
97
- // Run benchmarks sequentially
98
- async function runBenchmarks() {
99
- const results = {};
100
-
101
- for (const scenario of scenarios) {
102
- console.log('─'.repeat(70));
103
- console.log(`šŸ“Š Benchmarking: ${scenario.name}`);
104
- console.log('─'.repeat(70));
105
-
106
- const result = await runBenchmark(scenario);
107
- results[scenario.name] = result;
108
-
109
- // Wait a bit between tests
110
- await sleep(2000);
111
- }
112
-
113
- return results;
114
- }
115
-
116
- function runBenchmark(scenario) {
117
- return new Promise((resolve, reject) => {
118
- const instance = autocannon({
119
- url: scenario.url,
120
- connections: scenario.connections,
121
- duration: scenario.duration,
122
- pipelining: 1,
123
- }, (err, result) => {
124
- if (err) {
125
- reject(err);
126
- } else {
127
- printResults(result, scenario.name);
128
- resolve(formatResults(result, scenario.name));
129
- }
130
- });
131
-
132
- autocannon.track(instance, { renderProgressBar: true });
133
- });
134
- }
135
-
136
- function printResults(result, name) {
137
- console.log(`\nāœ“ ${name} - Results:`);
138
- console.log(` Requests/sec: ${result.requests.average.toFixed(2)}`);
139
- console.log(` Latency (avg): ${result.latency.mean.toFixed(2)}ms`);
140
- console.log(` Latency (p50): ${result.latency.p50.toFixed(2)}ms`);
141
- console.log(` Latency (p99): ${result.latency.p99.toFixed(2)}ms`);
142
- console.log(` Throughput: ${(result.throughput.average / 1024 / 1024).toFixed(2)} MB/sec`);
143
- console.log(` Total requests: ${result.requests.total}`);
144
- console.log('');
145
- }
146
-
147
- function formatResults(result, name) {
148
- return {
149
- name,
150
- requestsPerSecond: result.requests.average,
151
- latency: {
152
- mean: result.latency.mean,
153
- p50: result.latency.p50,
154
- p75: result.latency.p75,
155
- p90: result.latency.p90,
156
- p99: result.latency.p99,
157
- p999: result.latency.p999
158
- },
159
- throughput: result.throughput.average,
160
- totalRequests: result.requests.total,
161
- errors: result.errors
162
- };
163
- }
164
-
165
- function sleep(ms) {
166
- return new Promise(resolve => setTimeout(resolve, ms));
167
- }
168
-
169
- // Main execution
170
- runBenchmarks()
171
- .then(results => {
172
- console.log('='.repeat(70));
173
- console.log('šŸ“‹ BENCHMARK SUMMARY');
174
- console.log('='.repeat(70));
175
- console.log('');
176
-
177
- // Summary table
178
- console.log('Scenario | Req/sec | Latency (avg) | Throughput');
179
- console.log('----------------------------------|---------|---------------|-------------');
180
-
181
- Object.values(results).forEach(result => {
182
- const name = result.name.padEnd(33);
183
- const reqSec = result.requestsPerSecond.toFixed(0).padStart(7);
184
- const latency = `${result.latency.mean.toFixed(2)}ms`.padStart(13);
185
- const throughput = `${(result.throughput / 1024 / 1024).toFixed(2)} MB/s`.padStart(11);
186
- console.log(`${name} | ${reqSec} | ${latency} | ${throughput}`);
187
- });
188
-
189
- console.log('');
190
- console.log('='.repeat(70));
191
-
192
- // Save results if requested
193
- if (saveFile) {
194
- const data = {
195
- timestamp: new Date().toISOString(),
196
- version: require('./package.json').version,
197
- results
198
- };
199
- fs.writeFileSync(saveFile, JSON.stringify(data, null, 2));
200
- console.log(`\nāœ“ Results saved to: ${saveFile}`);
201
- }
202
-
203
- // Compare with previous results if requested
204
- if (compareFile && fs.existsSync(compareFile)) {
205
- const previous = JSON.parse(fs.readFileSync(compareFile, 'utf8'));
206
- console.log('\nšŸ“Š COMPARISON WITH PREVIOUS RESULTS');
207
- console.log('='.repeat(70));
208
-
209
- Object.keys(results).forEach(key => {
210
- const current = results[key];
211
- const prev = previous.results[key];
212
-
213
- if (prev) {
214
- const reqDiff = ((current.requestsPerSecond - prev.requestsPerSecond) / prev.requestsPerSecond * 100);
215
- const latDiff = ((current.latency.mean - prev.latency.mean) / prev.latency.mean * 100);
216
-
217
- console.log(`\n${key}:`);
218
- console.log(` Requests/sec: ${prev.requestsPerSecond.toFixed(2)} → ${current.requestsPerSecond.toFixed(2)} (${reqDiff > 0 ? '+' : ''}${reqDiff.toFixed(1)}%)`);
219
- console.log(` Latency: ${prev.latency.mean.toFixed(2)}ms → ${current.latency.mean.toFixed(2)}ms (${latDiff > 0 ? '+' : ''}${latDiff.toFixed(1)}%)`);
220
-
221
- if (reqDiff > 10) {
222
- console.log(` āœ… Significant improvement!`);
223
- } else if (reqDiff < -10) {
224
- console.log(` āš ļø Performance regression!`);
225
- }
226
- }
227
- });
228
-
229
- console.log('\n' + '='.repeat(70));
230
- }
231
-
232
- server.close();
233
- console.log('\nāœ“ Benchmark complete!\n');
234
- })
235
- .catch(err => {
236
- console.error('āŒ Benchmark failed:', err);
237
- server.close();
238
- process.exit(1);
239
- });