koa-classic-server 3.0.0 → 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 (105) hide show
  1. package/README.md +44 -120
  2. package/index.cjs +236 -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__/hidden-fixtures/.dot-dir/inside.txt +0 -1
  24. package/__tests__/hidden-fixtures/.env +0 -2
  25. package/__tests__/hidden-fixtures/.well-known/acme-challenge.txt +0 -1
  26. package/__tests__/hidden-fixtures/config/secrets/password.txt +0 -1
  27. package/__tests__/hidden-fixtures/data.key +0 -1
  28. package/__tests__/hidden-fixtures/file.secret +0 -1
  29. package/__tests__/hidden-fixtures/index.html +0 -1
  30. package/__tests__/hidden-fixtures/normal.txt +0 -1
  31. package/__tests__/hidden-fixtures/subdir/.env +0 -1
  32. package/__tests__/hidden-fixtures/subdir/regular.txt +0 -1
  33. package/__tests__/hidden-option.test.js +0 -407
  34. package/__tests__/hideExtension.test.js +0 -607
  35. package/__tests__/index-option.test.js +0 -449
  36. package/__tests__/index.test.js +0 -345
  37. package/__tests__/listing.test.js +0 -437
  38. package/__tests__/logger.test.js +0 -232
  39. package/__tests__/performance.test.js +0 -370
  40. package/__tests__/publicWwwTest/cartella/sottocartella/ciao.html +0 -11
  41. package/__tests__/publicWwwTest/cartella/sottocartella/provaEjs/testEjs.ejs +0 -11
  42. package/__tests__/publicWwwTest/cartella vuota con spazi nel nome/file con spazio nel nome .txt +0 -1
  43. package/__tests__/publicWwwTest/cartella vuota con spazi nel nome /file con spazio nel nome .txt +0 -1
  44. package/__tests__/publicWwwTest/ejs-templates/complex.ejs +0 -56
  45. package/__tests__/publicWwwTest/ejs-templates/index.ejs +0 -30
  46. package/__tests__/publicWwwTest/ejs-templates/simple.ejs +0 -13
  47. package/__tests__/publicWwwTest/ejs-templates/with-conditional.ejs +0 -28
  48. package/__tests__/publicWwwTest/ejs-templates/with-escaping.ejs +0 -26
  49. package/__tests__/publicWwwTest/ejs-templates/with-loop.ejs +0 -16
  50. package/__tests__/publicWwwTest/hideext-test/about/index.html +0 -1
  51. package/__tests__/publicWwwTest/hideext-test/about.EJS +0 -1
  52. package/__tests__/publicWwwTest/hideext-test/about.ejs +0 -2
  53. package/__tests__/publicWwwTest/hideext-test/blog/articolo.ejs +0 -2
  54. package/__tests__/publicWwwTest/hideext-test/conflict-test/pagina +0 -1
  55. package/__tests__/publicWwwTest/hideext-test/conflict-test/pagina.ejs +0 -1
  56. package/__tests__/publicWwwTest/hideext-test/file.ejs.bak +0 -1
  57. package/__tests__/publicWwwTest/hideext-test/index.ejs +0 -2
  58. package/__tests__/publicWwwTest/hideext-test/photo.txt +0 -1
  59. package/__tests__/publicWwwTest/hideext-test/sezione/index.ejs +0 -1
  60. package/__tests__/publicWwwTest/hideext-test/style.css +0 -1
  61. package/__tests__/publicWwwTest/ile_vuoto.txt +0 -0
  62. package/__tests__/publicWwwTest/index.html +0 -11
  63. package/__tests__/publicWwwTest/prova file .txt +0 -2
  64. package/__tests__/publicWwwTest/semplicetxt.txt +0 -1
  65. package/__tests__/publicWwwTest/test-page.html +0 -1
  66. package/__tests__/publicWwwTest/test.txt +0 -1
  67. package/__tests__/range-fixtures/sample.txt +0 -1
  68. package/__tests__/range.test.js +0 -223
  69. package/__tests__/security-headers.test.js +0 -165
  70. package/__tests__/security.test.js +0 -322
  71. package/__tests__/server-cache-fixtures/large.txt +0 -1
  72. package/__tests__/server-cache-fixtures/small.txt +0 -1
  73. package/__tests__/server-cache.test.js +0 -594
  74. package/__tests__/setup-benchmark.js +0 -178
  75. package/__tests__/symlink.test.js +0 -441
  76. package/__tests__/template-timeout.test.js +0 -321
  77. package/__tests__/test-regex-quick.js +0 -158
  78. package/__tests__/useOriginalUrl.test.js +0 -213
  79. package/docs/ACTION_PLAN.md +0 -293
  80. package/docs/BENCHMARKS.md +0 -317
  81. package/docs/CHANGELOG.md +0 -880
  82. package/docs/CODE_REVIEW.md +0 -300
  83. package/docs/DEBUG_REPORT.md +0 -593
  84. package/docs/DOCUMENTATION.md +0 -1864
  85. package/docs/EXAMPLES_INDEX_OPTION.md +0 -395
  86. package/docs/FLOW_DIAGRAM.md +0 -954
  87. package/docs/INDEX_OPTION_PRIORITY.md +0 -527
  88. package/docs/OPTIMIZATION_HTTP_CACHING.md +0 -689
  89. package/docs/OPTIMIZATION_ROADMAP_for_V3.md +0 -864
  90. package/docs/PERFORMANCE_ANALYSIS.md +0 -839
  91. package/docs/PERFORMANCE_COMPARISON.md +0 -388
  92. package/docs/noteExports.md +0 -148
  93. package/docs/security_improvement_for_V3.md +0 -421
  94. package/docs/template-engine/TEMPLATE_ENGINE_GUIDE.md +0 -1734
  95. package/docs/template-engine/esempi-incrementali.js +0 -192
  96. package/docs/template-engine/examples/esempio1-nessun-dato.ejs +0 -12
  97. package/docs/template-engine/examples/esempio2-una-variabile.ejs +0 -11
  98. package/docs/template-engine/examples/esempio3-piu-variabili.ejs +0 -15
  99. package/docs/template-engine/examples/esempio4-condizionale.ejs +0 -18
  100. package/docs/template-engine/examples/esempio5-loop.ejs +0 -18
  101. package/docs/template-engine/examples/index-esempi.html +0 -181
  102. package/docs/template-engine/examples/index.html +0 -40
  103. package/docs/template-engine/examples/test.ejs +0 -64
  104. package/eslint.config.mjs +0 -17
  105. package/jest.config.js +0 -18
@@ -1,300 +0,0 @@
1
- # Code Review - koa-classic-server
2
-
3
- > **Nota storica:** questo documento è uno snapshot di code review precedente al refactor V3. Riferimenti a `showDirContents` corrispondono a `dirListing.enabled` nell'API V3 corrente. Vedi [README.md → Migration Guide](../README.md#from-v2x-to-v3x).
4
-
5
- ## Analisi Generale del Codice
6
-
7
- Data: 2025-11-18
8
- File analizzato: `index.cjs` (651 righe)
9
- Test: 146 passing ✅
10
-
11
- ---
12
-
13
- ## 📊 Sommario
14
-
15
- | Categoria | Stato | Note |
16
- |-----------|-------|------|
17
- | Indentazione | ✅ Ottima | Consistente a 4 spazi |
18
- | Gestione errori | ✅ Ottima | Try/catch completi |
19
- | Sicurezza | ✅ Ottima | Path traversal, XSS protection |
20
- | Performance | ✅ Ottima | Async/await, array join |
21
- | Test coverage | ✅ Ottima | 146 test passano |
22
- | **Operatori confronto** | ⚠️ **Da migliorare** | Uso misto di `==` e `===` |
23
-
24
- ---
25
-
26
- ## ⚠️ Problemi Trovati
27
-
28
- ### 1. Uso Inconsistente di == vs ===
29
-
30
- **Problema:** Il codice usa sia `==` che `===` in modo inconsistente.
31
-
32
- **Impatto:** Medio - Può causare bug sottili dovuti alla type coercion JavaScript.
33
-
34
- **Occorrenze trovate:** ~25 istanze
35
-
36
- #### Esempi:
37
-
38
- **Linea 68:**
39
- ```javascript
40
- // ❌ Attuale
41
- options.showDirContents = typeof options.showDirContents == 'boolean' ? options.showDirContents : true;
42
-
43
- // ✅ Suggerito
44
- options.showDirContents = typeof options.showDirContents === 'boolean' ? options.showDirContents : true;
45
- ```
46
-
47
- **Linea 112:**
48
- ```javascript
49
- // ❌ Attuale
50
- if (ctx.href.charAt(ctx.href.length - 1) == '/') {
51
-
52
- // ✅ Suggerito
53
- if (ctx.href.charAt(ctx.href.length - 1) === '/') {
54
- ```
55
-
56
- **Linea 123:**
57
- ```javascript
58
- // ❌ Attuale
59
- if (a_urlPrefix[key] != a_pathname[key]) {
60
-
61
- // ✅ Suggerito
62
- if (a_urlPrefix[key] !== a_pathname[key]) {
63
- ```
64
-
65
- **Linea 470:**
66
- ```javascript
67
- // ❌ Attuale
68
- if (dir.length == 0) {
69
-
70
- // ✅ Suggerito
71
- if (dir.length === 0) {
72
- ```
73
-
74
- **Linea 500:**
75
- ```javascript
76
- // ❌ Attuale
77
- if (type == 1) {
78
-
79
- // ✅ Suggerito
80
- if (type === 1) {
81
- ```
82
-
83
- ---
84
-
85
- ### 2. Lista Completa Sostituzioni Richieste
86
-
87
- #### typeof comparisons (5 occorrenze):
88
- ```javascript
89
- Linea 68: typeof options.showDirContents == 'boolean' → ===
90
- Linea 71: typeof options.index == 'string' → ===
91
- Linea 94: typeof options.urlPrefix == 'string' → ===
92
- Linea 96: options.template.render == undefined → ===
93
- Linea 96: typeof options.template.render == 'function' → ===
94
- Linea 100: typeof options.cacheMaxAge == 'number' → ===
95
- Linea 101: typeof options.enableCaching == 'boolean' → ===
96
- ```
97
-
98
- #### String comparisons (5 occorrenze):
99
- ```javascript
100
- Linea 112: ctx.href.charAt(ctx.href.length - 1) == '/' → ===
101
- Linea 123: a_urlPrefix[key] != a_pathname[key] → !==
102
- Linea 131: options.urlPrefix != "" → !==
103
- Linea 152: pageHrefOutPrefix.pathname == "/" → ===
104
- Linea 462: pageHrefOutPrefix.origin + "/" != pageHrefOutPrefix.href → !==
105
- Linea 489: pageHref.href == pageHref.origin + options.urlPrefix + "/" → ===
106
- ```
107
-
108
- #### Number comparisons (8 occorrenze):
109
- ```javascript
110
- Linea 142: a_pathnameOutPrefix[1] == value.substring(1) → ===
111
- Linea 470: dir.length == 0 → ===
112
- Linea 482: type !== 1 && type !== 2 && type !== 3 → ✅ già corretto
113
- Linea 500: type == 1 → ===
114
- Linea 510: type == 2 → ===
115
- Linea 511: type == 2 || type == 3 → === (2 volte)
116
- Linea 532: a.type === 2 → ✅ già corretto
117
- Linea 534: a.type !== 2 && b.type === 2 → ✅ già corretto
118
- Linea 542: a.type === 2 && b.type !== 2 → ✅ già corretto
119
- Linea 557: item.type == 1 → ===
120
- ```
121
-
122
- ---
123
-
124
- ## ✅ Punti di Forza
125
-
126
- ### 1. Sicurezza
127
- - ✅ Path traversal protection completa (linea 149-168)
128
- - ✅ XSS protection con `escapeHtml()` (linea 524-534)
129
- - ✅ Content-Disposition properly quoted (linea 379-383)
130
- - ✅ Validazione input robusta
131
-
132
- ### 2. Performance
133
- - ✅ Tutte le operazioni I/O sono async (non bloccanti)
134
- - ✅ String concatenation sostituita con array join
135
- - ✅ HTTP caching con ETag e Last-Modified
136
- - ✅ Conditional requests (304 Not Modified)
137
-
138
- ### 3. Gestione Errori
139
- - ✅ Try/catch su tutte le operazioni async
140
- - ✅ Status code corretti (404, 403, 500)
141
- - ✅ Gestione race conditions
142
- - ✅ Fallback appropriati
143
-
144
- ### 4. Codice Pulito
145
- - ✅ Indentazione consistente (4 spazi)
146
- - ✅ Commenti chiari e utili
147
- - ✅ Nomi variabili descrittivi
148
- - ✅ Funzioni ben separate
149
-
150
- ---
151
-
152
- ## 💡 Raccomandazioni
153
-
154
- ### Priorità Alta
155
-
156
- 1. **Standardizzare operatori di confronto**
157
- - Sostituire tutti i `==` con `===`
158
- - Sostituire tutti i `!=` con `!==`
159
- - Motivo: Prevenire bug dovuti a type coercion
160
- - Tempo stimato: 10-15 minuti
161
- - Rischio: Basso (test coprono il comportamento)
162
-
163
- ### Priorità Media
164
-
165
- 2. **Aggiungere JSDoc comments**
166
- ```javascript
167
- /**
168
- * Find index file in directory with priority support
169
- * @param {string} dirPath - Directory path to search
170
- * @param {Array<string|RegExp>} indexPatterns - Array of patterns
171
- * @returns {Promise<{name: string, stat: fs.Stats}|null>}
172
- */
173
- async function findIndexFile(dirPath, indexPatterns) {
174
- // ...
175
- }
176
- ```
177
-
178
- 3. **Separare funzioni helper in moduli**
179
- - `escapeHtml()` → `lib/htmlUtils.js`
180
- - `formatSize()` → `lib/formatUtils.js`
181
- - Miglior organizzazione e testabilità
182
-
183
- ### Priorità Bassa
184
-
185
- 4. **Aggiungere TypeScript definitions** (`index.d.ts`)
186
- 5. **Considerare ESLint** per standardizzazione automatica
187
-
188
- ---
189
-
190
- ## 🧪 Verifica Sicurezza
191
-
192
- ### Path Traversal Protection ✅
193
- ```javascript
194
- // Linea 149-168
195
- const normalizedPath = path.normalize(requestedPath);
196
- const fullPath = path.join(normalizedRootDir, normalizedPath);
197
-
198
- // Security check: ensure resolved path is within rootDir
199
- if (!fullPath.startsWith(normalizedRootDir)) {
200
- ctx.status = 403;
201
- ctx.body = 'Forbidden';
202
- return;
203
- }
204
- ```
205
- **Valutazione:** Eccellente. Protegge da `../../../etc/passwd` attacks.
206
-
207
- ### XSS Protection ✅
208
- ```javascript
209
- // Linea 524-534
210
- function escapeHtml(unsafe) {
211
- if (typeof unsafe !== 'string') {
212
- return unsafe;
213
- }
214
- return unsafe
215
- .replace(/&/g, "&amp;")
216
- .replace(/</g, "&lt;")
217
- .replace(/>/g, "&gt;")
218
- .replace(/"/g, "&quot;")
219
- .replace(/'/g, "&#039;");
220
- }
221
- ```
222
- **Valutazione:** Eccellente. Previene XSS in directory listing.
223
-
224
- ### Race Condition Protection ✅
225
- ```javascript
226
- // Linea 174-181
227
- try {
228
- stat = await fs.promises.stat(toOpen);
229
- } catch (error) {
230
- ctx.status = 404;
231
- ctx.body = requestedUrlNotFound();
232
- return;
233
- }
234
- ```
235
- **Valutazione:** Buona. Gestisce correttamente file cancellati tra check ed access.
236
-
237
- ---
238
-
239
- ## 📈 Metriche Codice
240
-
241
- | Metrica | Valore | Valutazione |
242
- |---------|--------|-------------|
243
- | Linee codice | 651 | ✅ Appropriato |
244
- | Complessità ciclomatica | Bassa | ✅ Ottimo |
245
- | Funzioni async | 100% | ✅ Eccellente |
246
- | Copertura test | Alta | ✅ Eccellente |
247
- | Dipendenze | 4 | ✅ Minime |
248
-
249
- ---
250
-
251
- ## 🎯 Piano d'Azione Suggerito
252
-
253
- ### Step 1: Fix operatori confronto (15 min)
254
- ```bash
255
- # Trova tutte le occorrenze
256
- grep -n " == " index.cjs
257
- grep -n " != " index.cjs
258
-
259
- # Sostituisci manualmente o con script
260
- ```
261
-
262
- ### Step 2: Verifica test (2 min)
263
- ```bash
264
- npm test
265
- ```
266
-
267
- ### Step 3: Commit (1 min)
268
- ```bash
269
- git add index.cjs
270
- git commit -m "Standardize comparison operators (== to ===, != to !==)"
271
- ```
272
-
273
- ---
274
-
275
- ## 📝 Note Finali
276
-
277
- Il codice è **globalmente di ottima qualità**:
278
- - ✅ Sicuro
279
- - ✅ Performante
280
- - ✅ Ben testato
281
- - ✅ Ben strutturato
282
-
283
- L'unico miglioramento significativo è la **standardizzazione degli operatori di confronto** da `==` a `===`, che è una best practice JavaScript universalmente riconosciuta.
284
-
285
- **Rischio di modifiche:** Basso
286
- - I test esistenti coprono il comportamento
287
- - Le modifiche sono meccaniche
288
- - Nessun cambio di logica
289
-
290
- **Benefici:**
291
- - Codice più robusto
292
- - Prevenzione bug futuri
293
- - Conformità best practices
294
- - Migliore leggibilità
295
-
296
- ---
297
-
298
- **Review by:** Claude Code Assistant
299
- **Date:** 2025-11-18
300
- **Status:** ⚠️ Minor issues found - Easy fixes recommended