koa-classic-server 2.1.2 โ 2.1.3
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/.github/workflows/npm-publish.yml +98 -0
- package/README.md +16 -5
- package/docs/CHANGELOG.md +78 -0
- package/index.cjs +8 -2
- package/package.json +5 -1
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# This workflow will run tests using node and then publish a package to npm when a release is published
|
|
2
|
+
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
|
|
3
|
+
|
|
4
|
+
name: Publish to npm
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
release:
|
|
8
|
+
types: [published]
|
|
9
|
+
|
|
10
|
+
# Prevent multiple concurrent publish workflows
|
|
11
|
+
concurrency:
|
|
12
|
+
group: npm-publish-${{ github.ref }}
|
|
13
|
+
cancel-in-progress: false
|
|
14
|
+
|
|
15
|
+
# Set permissions for the workflow
|
|
16
|
+
permissions:
|
|
17
|
+
contents: read
|
|
18
|
+
id-token: write # Required for npm provenance
|
|
19
|
+
|
|
20
|
+
jobs:
|
|
21
|
+
build:
|
|
22
|
+
name: Build and Test
|
|
23
|
+
runs-on: ubuntu-latest
|
|
24
|
+
timeout-minutes: 10
|
|
25
|
+
|
|
26
|
+
steps:
|
|
27
|
+
- name: Checkout code
|
|
28
|
+
uses: actions/checkout@v4
|
|
29
|
+
|
|
30
|
+
- name: Setup Node.js
|
|
31
|
+
uses: actions/setup-node@v4
|
|
32
|
+
with:
|
|
33
|
+
node-version: 20
|
|
34
|
+
cache: 'npm'
|
|
35
|
+
|
|
36
|
+
- name: Install dependencies
|
|
37
|
+
run: npm ci
|
|
38
|
+
|
|
39
|
+
- name: Run tests
|
|
40
|
+
run: npm test --if-present
|
|
41
|
+
|
|
42
|
+
- name: Build package
|
|
43
|
+
run: npm run build --if-present
|
|
44
|
+
|
|
45
|
+
- name: Cache build artifacts
|
|
46
|
+
uses: actions/cache/save@v4
|
|
47
|
+
with:
|
|
48
|
+
path: |
|
|
49
|
+
node_modules
|
|
50
|
+
dist
|
|
51
|
+
build
|
|
52
|
+
key: build-${{ github.sha }}
|
|
53
|
+
|
|
54
|
+
publish-npm:
|
|
55
|
+
name: Publish to npm Registry
|
|
56
|
+
needs: build
|
|
57
|
+
runs-on: ubuntu-latest
|
|
58
|
+
timeout-minutes: 10
|
|
59
|
+
|
|
60
|
+
steps:
|
|
61
|
+
- name: Checkout code
|
|
62
|
+
uses: actions/checkout@v4
|
|
63
|
+
|
|
64
|
+
- name: Setup Node.js
|
|
65
|
+
uses: actions/setup-node@v4
|
|
66
|
+
with:
|
|
67
|
+
node-version: 20
|
|
68
|
+
registry-url: https://registry.npmjs.org/
|
|
69
|
+
cache: 'npm'
|
|
70
|
+
|
|
71
|
+
- name: Restore build artifacts
|
|
72
|
+
uses: actions/cache/restore@v4
|
|
73
|
+
with:
|
|
74
|
+
path: |
|
|
75
|
+
node_modules
|
|
76
|
+
dist
|
|
77
|
+
build
|
|
78
|
+
key: build-${{ github.sha }}
|
|
79
|
+
|
|
80
|
+
- name: Verify package version matches release tag
|
|
81
|
+
run: |
|
|
82
|
+
PACKAGE_VERSION=$(node -p "require('./package.json').version")
|
|
83
|
+
RELEASE_TAG=${GITHUB_REF#refs/tags/}
|
|
84
|
+
# Remove 'v' prefix if present in tag
|
|
85
|
+
RELEASE_VERSION=${RELEASE_TAG#v}
|
|
86
|
+
|
|
87
|
+
echo "Package version: $PACKAGE_VERSION"
|
|
88
|
+
echo "Release version: $RELEASE_VERSION"
|
|
89
|
+
|
|
90
|
+
if [ "$PACKAGE_VERSION" != "$RELEASE_VERSION" ]; then
|
|
91
|
+
echo "Error: Package version ($PACKAGE_VERSION) does not match release tag ($RELEASE_VERSION)"
|
|
92
|
+
exit 1
|
|
93
|
+
fi
|
|
94
|
+
|
|
95
|
+
- name: Publish to npm with provenance
|
|
96
|
+
run: npm publish --provenance --access public
|
|
97
|
+
env:
|
|
98
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/README.md
CHANGED
|
@@ -8,9 +8,15 @@
|
|
|
8
8
|
|
|
9
9
|
---
|
|
10
10
|
|
|
11
|
-
## ๐ Version 2.1.
|
|
11
|
+
## ๐ Version 2.1.3 - Configuration Update
|
|
12
12
|
|
|
13
|
-
Version 2.1.
|
|
13
|
+
Version 2.1.3 updates the default caching behavior for better development experience while maintaining production-ready performance.
|
|
14
|
+
|
|
15
|
+
### What's New in 2.1.3
|
|
16
|
+
|
|
17
|
+
โ
**Development-Friendly Defaults** - `enableCaching` now defaults to `false` for easier development
|
|
18
|
+
โ
**Production Guidance** - Clear documentation on enabling caching for production environments
|
|
19
|
+
โ
**Enhanced Documentation** - Comprehensive notes on caching configuration and recommendations
|
|
14
20
|
|
|
15
21
|
### What's New in 2.1.2
|
|
16
22
|
|
|
@@ -228,10 +234,14 @@ app.use(koaClassicServer(__dirname + '/public', {
|
|
|
228
234
|
}));
|
|
229
235
|
```
|
|
230
236
|
|
|
231
|
-
**
|
|
237
|
+
**โ ๏ธ Important: Production Recommendation**
|
|
238
|
+
|
|
239
|
+
The default value for `enableCaching` is `false` to facilitate development (where you want changes to be immediately visible). **For production environments, it is strongly recommended to set `enableCaching: true`** to benefit from:
|
|
240
|
+
|
|
232
241
|
- 80-95% bandwidth reduction
|
|
233
242
|
- 304 Not Modified responses for unchanged files
|
|
234
243
|
- Faster page loads for returning visitors
|
|
244
|
+
- Reduced server load
|
|
235
245
|
|
|
236
246
|
**See details:** [HTTP Caching Optimization โ](./docs/OPTIMIZATION_HTTP_CACHING.md)
|
|
237
247
|
|
|
@@ -357,7 +367,8 @@ Creates a Koa middleware for serving static files.
|
|
|
357
367
|
},
|
|
358
368
|
|
|
359
369
|
// HTTP caching configuration
|
|
360
|
-
|
|
370
|
+
// NOTE: Default is false for development. Set to true in production for better performance!
|
|
371
|
+
enableCaching: false, // Enable ETag & Last-Modified (default: false)
|
|
361
372
|
cacheMaxAge: 3600, // Cache-Control max-age in seconds (default: 3600 = 1 hour)
|
|
362
373
|
}
|
|
363
374
|
```
|
|
@@ -373,7 +384,7 @@ Creates a Koa middleware for serving static files.
|
|
|
373
384
|
| `urlsReserved` | Array | `[]` | Reserved directory paths (first-level only) |
|
|
374
385
|
| `template.render` | Function | `undefined` | Template rendering function |
|
|
375
386
|
| `template.ext` | Array | `[]` | Extensions for template rendering |
|
|
376
|
-
| `enableCaching` | Boolean | `
|
|
387
|
+
| `enableCaching` | Boolean | `false` | Enable HTTP caching headers (recommended: `true` in production) |
|
|
377
388
|
| `cacheMaxAge` | Number | `3600` | Cache duration in seconds |
|
|
378
389
|
|
|
379
390
|
---
|
package/docs/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,84 @@ All notable changes to koa-classic-server will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [2.1.3] - 2025-11-25
|
|
9
|
+
|
|
10
|
+
### ๐ง Configuration Changes
|
|
11
|
+
|
|
12
|
+
#### Changed Default Caching Behavior
|
|
13
|
+
- **Change**: `enableCaching` default value changed from `true` to `false`
|
|
14
|
+
- **Rationale**: Better development experience - changes are immediately visible without cache invalidation
|
|
15
|
+
- **Production Impact**: **Users should explicitly set `enableCaching: true` in production environments**
|
|
16
|
+
- **Benefits in Production**:
|
|
17
|
+
- 80-95% bandwidth reduction
|
|
18
|
+
- Faster page loads with 304 Not Modified responses
|
|
19
|
+
- Reduced server load
|
|
20
|
+
- **Code**: `index.cjs:107`
|
|
21
|
+
|
|
22
|
+
### ๐ Documentation Improvements
|
|
23
|
+
|
|
24
|
+
#### Enhanced Caching Documentation
|
|
25
|
+
- Added comprehensive production recommendations in README.md
|
|
26
|
+
- Added inline code comments explaining the default behavior
|
|
27
|
+
- Clear guidance on when to enable caching (development vs production)
|
|
28
|
+
- **Files**: `README.md`, `index.cjs`
|
|
29
|
+
|
|
30
|
+
### โ ๏ธ Migration Notice
|
|
31
|
+
|
|
32
|
+
**IMPORTANT**: If you are upgrading from 2.1.2 or earlier and rely on HTTP caching:
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
// You must now explicitly enable caching in production
|
|
36
|
+
app.use(koaClassicServer(__dirname + '/public', {
|
|
37
|
+
enableCaching: true // โ Add this for production environments
|
|
38
|
+
}));
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**Development**: No changes needed - the new default (`false`) is better for development.
|
|
42
|
+
|
|
43
|
+
**Production**: Explicitly set `enableCaching: true` to maintain previous behavior and performance benefits.
|
|
44
|
+
|
|
45
|
+
### ๐ฆ Package Changes
|
|
46
|
+
|
|
47
|
+
- **Version**: `2.1.2` โ `2.1.3`
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## [2.1.2] - 2025-11-24
|
|
52
|
+
|
|
53
|
+
### ๐จ Features
|
|
54
|
+
|
|
55
|
+
#### Sortable Directory Columns
|
|
56
|
+
- Apache2-like directory listing with clickable column headers
|
|
57
|
+
- Sort by Name, Type, or Size (ascending/descending)
|
|
58
|
+
- Fixed navigation bug after sorting
|
|
59
|
+
|
|
60
|
+
#### File Size Display
|
|
61
|
+
- Human-readable file sizes (B, KB, MB, GB, TB)
|
|
62
|
+
- Proper formatting and precision
|
|
63
|
+
|
|
64
|
+
#### HTTP Caching
|
|
65
|
+
- ETag and Last-Modified headers
|
|
66
|
+
- 304 Not Modified responses
|
|
67
|
+
- 80-95% bandwidth reduction
|
|
68
|
+
|
|
69
|
+
### ๐งช Testing
|
|
70
|
+
- 153 tests passing
|
|
71
|
+
- Comprehensive test coverage
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## [2.1.1] - 2025-11-23
|
|
76
|
+
|
|
77
|
+
### ๐ Production Release
|
|
78
|
+
|
|
79
|
+
- Async/await implementation
|
|
80
|
+
- Non-blocking I/O
|
|
81
|
+
- Performance optimizations
|
|
82
|
+
- Flow documentation
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
8
86
|
## [1.2.0] - 2025-11-17
|
|
9
87
|
|
|
10
88
|
### ๐ SECURITY & BUG FIX RELEASE
|
package/index.cjs
CHANGED
|
@@ -45,7 +45,10 @@ module.exports = function koaClassicServer(
|
|
|
45
45
|
ext: [], // File extensions to process with template.render
|
|
46
46
|
},
|
|
47
47
|
cacheMaxAge: 3600, // Cache-Control max-age in seconds (default: 1 hour)
|
|
48
|
-
enableCaching:
|
|
48
|
+
enableCaching: false, // Enable HTTP caching headers (ETag, Last-Modified)
|
|
49
|
+
// NOTE: Default is false for development.
|
|
50
|
+
// In production, it's recommended to set enableCaching: true
|
|
51
|
+
// to reduce bandwidth usage and improve performance.
|
|
49
52
|
}
|
|
50
53
|
*/
|
|
51
54
|
) {
|
|
@@ -97,8 +100,11 @@ module.exports = function koaClassicServer(
|
|
|
97
100
|
options.template.ext = Array.isArray(options.template.ext) ? options.template.ext : [];
|
|
98
101
|
|
|
99
102
|
// OPTIMIZATION: HTTP Caching options
|
|
103
|
+
// NOTE: Default enableCaching is false for development environments.
|
|
104
|
+
// For production deployments, it's strongly recommended to enable caching
|
|
105
|
+
// by setting enableCaching: true to benefit from reduced bandwidth and improved performance.
|
|
100
106
|
options.cacheMaxAge = typeof options.cacheMaxAge === 'number' && options.cacheMaxAge >= 0 ? options.cacheMaxAge : 3600;
|
|
101
|
-
options.enableCaching = typeof options.enableCaching === 'boolean' ? options.enableCaching :
|
|
107
|
+
options.enableCaching = typeof options.enableCaching === 'boolean' ? options.enableCaching : false;
|
|
102
108
|
|
|
103
109
|
return async (ctx, next) => {
|
|
104
110
|
// Check if method is allowed
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koa-classic-server",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"description": "High-performance Koa middleware for serving static files with Apache-like directory listing, HTTP caching, template engine support, and comprehensive security fixes",
|
|
5
5
|
"main": "index.cjs",
|
|
6
6
|
"exports": {
|
|
@@ -29,6 +29,10 @@
|
|
|
29
29
|
],
|
|
30
30
|
"author": "Italo Paesano",
|
|
31
31
|
"license": "MIT",
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/italopaesano/koa-classic-server"
|
|
35
|
+
},
|
|
32
36
|
"dependencies": {
|
|
33
37
|
"mime-types": "^2.1.35"
|
|
34
38
|
},
|