koa-classic-server 2.6.1 → 3.0.0-alpha.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 +68 -10
- package/__tests__/caching-headers.test.js +30 -30
- package/__tests__/compression-fixtures/data.json +1 -0
- package/__tests__/compression-fixtures/large.txt +1 -0
- package/__tests__/compression-fixtures/small.txt +1 -0
- package/__tests__/compression.test.js +270 -0
- package/__tests__/customTest/serversToLoad.util.js +1 -1
- package/__tests__/deprecation-warnings.test.js +71 -183
- package/__tests__/dt-unknown.test.js +20 -9
- package/__tests__/hidden-fixtures/.dot-dir/inside.txt +1 -0
- package/__tests__/hidden-fixtures/.env +2 -0
- package/__tests__/hidden-fixtures/.well-known/acme-challenge.txt +1 -0
- package/__tests__/hidden-fixtures/config/secrets/password.txt +1 -0
- package/__tests__/hidden-fixtures/data.key +1 -0
- package/__tests__/hidden-fixtures/file.secret +1 -0
- package/__tests__/hidden-fixtures/index.html +1 -0
- package/__tests__/hidden-fixtures/normal.txt +1 -0
- package/__tests__/hidden-fixtures/subdir/.env +1 -0
- package/__tests__/hidden-fixtures/subdir/regular.txt +1 -0
- package/__tests__/hidden-option.test.js +422 -0
- package/__tests__/index-option.test.js +18 -16
- package/__tests__/index.test.js +8 -4
- package/__tests__/range-fixtures/sample.txt +1 -0
- package/__tests__/range.test.js +223 -0
- package/__tests__/security-headers.test.js +153 -0
- package/__tests__/security.test.js +145 -159
- package/__tests__/server-cache-fixtures/large.txt +1 -0
- package/__tests__/server-cache-fixtures/small.txt +1 -0
- package/__tests__/server-cache.test.js +423 -0
- package/__tests__/symlink.test.js +8 -5
- package/docs/ACTION_PLAN.md +293 -0
- package/docs/CHANGELOG.md +84 -0
- package/docs/EXAMPLES_INDEX_OPTION.md +2 -2
- package/docs/FLOW_DIAGRAM.md +13 -13
- package/docs/OPTIMIZATION_ROADMAP_for_V3.md +864 -0
- package/docs/PERFORMANCE_COMPARISON.md +7 -7
- package/eslint.config.mjs +17 -0
- package/index.cjs +1096 -391
- package/index.mjs +1 -5
- package/package.json +4 -1
|
@@ -222,21 +222,21 @@ app.use(koaClassicServer('/public'));
|
|
|
222
222
|
|
|
223
223
|
// Custom cache duration
|
|
224
224
|
app.use(koaClassicServer('/public', {
|
|
225
|
-
|
|
225
|
+
browserCacheMaxAge: 86400 // 24 hours
|
|
226
226
|
}));
|
|
227
227
|
|
|
228
228
|
// Disable caching (not recommended)
|
|
229
229
|
app.use(koaClassicServer('/public', {
|
|
230
|
-
|
|
230
|
+
browserCacheEnabled: false
|
|
231
231
|
}));
|
|
232
232
|
|
|
233
233
|
// Different strategies for different routes
|
|
234
234
|
app.use(koaClassicServer('/static-assets', {
|
|
235
|
-
|
|
235
|
+
browserCacheMaxAge: 31536000 // 1 year for immutable assets
|
|
236
236
|
}));
|
|
237
237
|
|
|
238
238
|
app.use(koaClassicServer('/dynamic-content', {
|
|
239
|
-
|
|
239
|
+
browserCacheMaxAge: 60 // 1 minute for frequently updated content
|
|
240
240
|
}));
|
|
241
241
|
```
|
|
242
242
|
|
|
@@ -320,13 +320,13 @@ app.use(koaClassicServer('/dynamic-content', {
|
|
|
320
320
|
|
|
321
321
|
2. **No code changes required** - caching is auto-enabled with sensible defaults
|
|
322
322
|
|
|
323
|
-
3. **Optional**: Configure `
|
|
323
|
+
3. **Optional**: Configure `browserCacheMaxAge` for your use case:
|
|
324
324
|
```javascript
|
|
325
325
|
// For static assets that rarely change
|
|
326
|
-
app.use(koaClassicServer('/assets', {
|
|
326
|
+
app.use(koaClassicServer('/assets', { browserCacheMaxAge: 31536000 }));
|
|
327
327
|
|
|
328
328
|
// For content that updates frequently
|
|
329
|
-
app.use(koaClassicServer('/content', {
|
|
329
|
+
app.use(koaClassicServer('/content', { browserCacheMaxAge: 300 }));
|
|
330
330
|
```
|
|
331
331
|
|
|
332
332
|
4. **Test caching** in browser DevTools:
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export default [
|
|
2
|
+
{
|
|
3
|
+
files: ['index.cjs', 'index.mjs'],
|
|
4
|
+
rules: {
|
|
5
|
+
// Enforce strict equality — prevents type coercion bugs.
|
|
6
|
+
// null exception: allows `x == null` as a safe idiom for (x === null || x === undefined).
|
|
7
|
+
'eqeqeq': ['error', 'always', { 'null': 'ignore' }],
|
|
8
|
+
|
|
9
|
+
// Forbid var — use const/let for block-scoped, predictable declarations.
|
|
10
|
+
'no-var': 'error',
|
|
11
|
+
|
|
12
|
+
// Flag unused variables — catch dead code and typos in variable names.
|
|
13
|
+
// args: 'after-used' allows unused leading args (e.g. (_, used) callbacks).
|
|
14
|
+
'no-unused-vars': ['error', { 'vars': 'all', 'args': 'after-used' }],
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
];
|