st 3.0.0 → 3.0.1

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.
@@ -0,0 +1,23 @@
1
+ name: Test
2
+ on: [push, pull_request]
3
+ jobs:
4
+ test:
5
+ strategy:
6
+ fail-fast: false
7
+ matrix:
8
+ node: [lts/*, current]
9
+ os: [macos-latest, ubuntu-latest, windows-latest]
10
+ runs-on: ${{ matrix.os }}
11
+ steps:
12
+ - name: Checkout Repository
13
+ uses: actions/checkout@v4
14
+ - name: Use Node.js ${{ matrix.node }}
15
+ uses: actions/setup-node@v4
16
+ with:
17
+ node-version: ${{ matrix.node }}
18
+ - name: Install Dependencies
19
+ run: |
20
+ npm install --no-progress
21
+ - name: Run tests
22
+ run: |
23
+ npm test
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "st",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "A module for serving static files. Does etags, caching, etc.",
5
5
  "main": "st.js",
6
6
  "bin": "bin/server.js",
package/st.js CHANGED
@@ -223,7 +223,10 @@ class Mount {
223
223
 
224
224
  // get a path from a url
225
225
  getPath (u) {
226
- return path.join(this.path, u)
226
+ // trailing slash removal to fix Node.js v23 bug
227
+ // https://github.com/nodejs/node/pull/55527
228
+ // can be removed when this is resolved and released
229
+ return path.join(this.path, u.replace(/\/+$/, ''))
227
230
  }
228
231
 
229
232
  // get a url from a path
package/test/basic.js CHANGED
@@ -97,6 +97,14 @@ test('multiball!', (t) => {
97
97
  }
98
98
  })
99
99
 
100
+ test('trailing slash', (t) => {
101
+ req('/test/test/fixtures/', (er, res, body) => {
102
+ t.equal(res.statusCode, 200)
103
+ t.ok(/<html>.*Index of \/test\/fixtures<[\s\S]+index\.html[\s\S]+space in filename\.txt[\s\S]+<\/html>/.test(body.toString()))
104
+ t.end()
105
+ })
106
+ })
107
+
100
108
  test('space in filename', (t) => {
101
109
  req('/test/test/fixtures/space in filename.txt', (er, res, body) => {
102
110
  t.equal(res.statusCode, 200)
@@ -1,4 +1,5 @@
1
1
  const os = require('os')
2
+ const dns = require('dns')
2
3
  let { test, fail, comment } = require('tap')
3
4
  const { serve } = require('./common')
4
5
  const port = 1338
@@ -73,12 +74,6 @@ testServer(
73
74
  ['127.0.0.1', 'localhost', otherAddress], []
74
75
  )
75
76
 
76
- testServer(
77
- 'Restricted to localhost',
78
- ['--localhost'], 'localhost',
79
- ['127.0.0.1', 'localhost'], [otherAddress]
80
- )
81
-
82
77
  testServer(
83
78
  'Restricted to non-local host',
84
79
  ['--host', otherAddress], otherAddress,
@@ -90,3 +85,14 @@ testServer(
90
85
  ['--host', '127.0.0.1'], '127.0.0.1',
91
86
  ['127.0.0.1'], ['::1']
92
87
  )
88
+
89
+ dns.lookup('localhost', (err, address) => {
90
+ if (err) {
91
+ throw err
92
+ }
93
+ testServer(
94
+ 'Restricted to localhost',
95
+ ['--localhost'], 'localhost',
96
+ [address, 'localhost'], [otherAddress]
97
+ )
98
+ })
@@ -90,7 +90,7 @@ test('setup middleware server', function (t) {
90
90
  })
91
91
  })
92
92
  })
93
- middlewareServer.listen(port, '127.0.0.1', function () {
93
+ middlewareServer.listen(port, 'localhost', function () {
94
94
  t.pass('listening')
95
95
  t.end()
96
96
  })
@@ -103,7 +103,7 @@ test('setup regular server', function (t) {
103
103
  return res.end(`Not a match: ${req.url}`)
104
104
  }
105
105
  })
106
- server.listen(port + 1, '127.0.0.1', function () {
106
+ server.listen(port + 1, 'localhost', function () {
107
107
  t.pass('listening')
108
108
  t.end()
109
109
  })
@@ -114,6 +114,7 @@ const stExpect = fs.readFileSync(require.resolve('../st.js')).toString()
114
114
 
115
115
  test('/test/st.js', function (t) {
116
116
  req('/test/st.js', function (er, res, body) {
117
+ t.error(er)
117
118
  t.equal(res.statusCode, 200)
118
119
  t.ok(res.headers.etag)
119
120
  stEtag = res.headers.etag