st 1.1.0 → 2.0.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/.travis.yml +13 -0
- package/README.md +36 -22
- package/bin/server.js +95 -60
- package/package.json +12 -10
- package/st.js +504 -445
- package/test/basic.js +57 -49
- package/test/cli/basic-test.js +32 -0
- package/test/cli/common.js +108 -0
- package/test/cli/host-test.js +92 -0
- package/test/common.js +42 -30
- package/test/cors.js +11 -13
- package/test/dot-common.js +25 -19
- package/test/dot-false.js +6 -8
- package/test/dot-true.js +8 -8
- package/test/gzip-after-no-gzip.js +12 -19
- package/test/middleware.js +8 -14
- package/test/multi-mount.js +100 -83
- package/test/no-cache.js +8 -10
- package/test/no-cors.js +4 -5
- package/test/no-gzip-accepted-no-cache.js +18 -25
- package/test/no-gzip-accepted.js +18 -24
- package/test/no-gzip.js +4 -9
- package/test/parent-path.js +1 -1
- package/test/passthrough.js +36 -42
- package/test/preset-cache-control.js +31 -27
- package/.npmignore +0 -1
package/test/passthrough.js
CHANGED
|
@@ -1,79 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var path = require('path')
|
|
1
|
+
const { test } = require('tap')
|
|
2
|
+
const path = require('path')
|
|
3
|
+
const st = require('../st.js')
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
const opts = Object.assign({
|
|
7
6
|
index: false,
|
|
8
7
|
path: path.resolve(__dirname, './fixtures'),
|
|
9
8
|
url: '/',
|
|
10
9
|
passthrough: true
|
|
11
10
|
}, global.options || {})
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
const mount = st(opts)
|
|
14
13
|
|
|
15
|
-
test('call next() if passthrough is set',
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
error:
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
setHeader: function () {},
|
|
22
|
-
end: function () {}
|
|
14
|
+
test('call next() if passthrough is set', (t) => {
|
|
15
|
+
const req = { method: 'GET', url: '/doesnotexist.txt', headers: {} }
|
|
16
|
+
const res = {
|
|
17
|
+
error: () => t.end(),
|
|
18
|
+
setHeader: () => {},
|
|
19
|
+
end: () => {}
|
|
23
20
|
}
|
|
24
21
|
t.plan(2)
|
|
25
|
-
mount(req, res,
|
|
26
|
-
t.ok(true,
|
|
27
|
-
req.url='/'
|
|
28
|
-
mount(req, res,
|
|
29
|
-
t.ok(true,
|
|
22
|
+
mount(req, res, () => {
|
|
23
|
+
t.ok(true, 'next called with nonexistant file')
|
|
24
|
+
req.url = '/'
|
|
25
|
+
mount(req, res, () => {
|
|
26
|
+
t.ok(true, 'next called without indexing')
|
|
30
27
|
t.end()
|
|
31
|
-
})
|
|
28
|
+
})
|
|
32
29
|
})
|
|
33
30
|
})
|
|
34
31
|
|
|
35
|
-
|
|
32
|
+
const opts2 = Object.assign({
|
|
36
33
|
autoindex: true,
|
|
37
34
|
path: path.resolve(__dirname, './fixtures'),
|
|
38
35
|
url: '/'
|
|
39
36
|
}, global.options || {})
|
|
40
|
-
mount2 = st(opts2)
|
|
37
|
+
const mount2 = st(opts2)
|
|
41
38
|
|
|
42
|
-
test('return error if passthrough is not set',
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
setHeader:
|
|
46
|
-
error:
|
|
47
|
-
t.ok(true,
|
|
39
|
+
test('return error if passthrough is not set', (t) => {
|
|
40
|
+
const req = { method: 'GET', url: '/doesnotexist.txt', headers: {} }
|
|
41
|
+
const res = {
|
|
42
|
+
setHeader: () => {},
|
|
43
|
+
error: () => {
|
|
44
|
+
t.ok(true, 'error used')
|
|
48
45
|
t.end()
|
|
49
46
|
},
|
|
50
|
-
end:
|
|
47
|
+
end: () => {}
|
|
51
48
|
}
|
|
52
49
|
t.plan(1)
|
|
53
|
-
mount2(req, res,
|
|
50
|
+
mount2(req, res, () => {
|
|
54
51
|
t.end()
|
|
55
52
|
})
|
|
56
53
|
})
|
|
57
54
|
|
|
58
|
-
test('does not set headers if passthrough is set',
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
error:
|
|
62
|
-
t.end()
|
|
63
|
-
},
|
|
55
|
+
test('does not set headers if passthrough is set', (t) => {
|
|
56
|
+
const req = { method: 'GET', url: '/doesnotexist.txt', headers: {} }
|
|
57
|
+
const res = {
|
|
58
|
+
error: () => t.end(),
|
|
64
59
|
_headers: [],
|
|
65
|
-
setHeader:
|
|
60
|
+
setHeader: (header) => {
|
|
66
61
|
res._headers.push(header)
|
|
67
62
|
},
|
|
68
|
-
end:
|
|
63
|
+
end: () => {}
|
|
69
64
|
}
|
|
70
65
|
t.plan(2)
|
|
71
|
-
mount(req, res,
|
|
72
|
-
|
|
66
|
+
mount(req, res, () => {
|
|
73
67
|
t.notOk(res._headers.length, 'headers are not set on a non-existant file')
|
|
74
|
-
req.url='/'
|
|
68
|
+
req.url = '/'
|
|
75
69
|
|
|
76
|
-
mount(req, res,
|
|
70
|
+
mount(req, res, () => {
|
|
77
71
|
t.notOk(res._headers.length, 'headers are not set with no index')
|
|
78
72
|
t.end()
|
|
79
73
|
})
|
|
@@ -1,60 +1,64 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var request = require('request')
|
|
8
|
-
var port = process.env.PORT || 1337
|
|
1
|
+
const st = require('../st.js')
|
|
2
|
+
const { test, tearDown } = require('tap')
|
|
3
|
+
const path = require('path')
|
|
4
|
+
const http = require('http')
|
|
5
|
+
const request = require('request')
|
|
6
|
+
const port = process.env.PORT || 1337
|
|
9
7
|
|
|
10
|
-
|
|
8
|
+
const opts = Object.assign({
|
|
11
9
|
index: false,
|
|
12
10
|
path: path.dirname(__dirname),
|
|
13
11
|
url: '/test'
|
|
14
12
|
}, global.options || {})
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
const mount = st(opts)
|
|
15
|
+
let server
|
|
16
|
+
let cacheControl = null
|
|
19
17
|
|
|
20
18
|
function req (url, headers, cb) {
|
|
21
|
-
if (typeof headers === 'function')
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
if (typeof headers === 'function') {
|
|
20
|
+
cb = headers
|
|
21
|
+
headers = {}
|
|
22
|
+
}
|
|
23
|
+
request({
|
|
24
|
+
encoding: null,
|
|
25
|
+
url: 'http://localhost:' + port + url,
|
|
26
|
+
headers: headers
|
|
27
|
+
}, cb)
|
|
25
28
|
}
|
|
26
29
|
|
|
27
|
-
|
|
28
|
-
server = http.createServer(
|
|
29
|
-
if (cacheControl)
|
|
30
|
+
test('setup', (t) => {
|
|
31
|
+
server = http.createServer((req, res) => {
|
|
32
|
+
if (cacheControl) {
|
|
30
33
|
res.setHeader('cache-control', cacheControl)
|
|
34
|
+
}
|
|
31
35
|
if (!mount(req, res)) {
|
|
32
36
|
res.statusCode = 404
|
|
33
37
|
return res.end('Not a match: ' + req.url)
|
|
34
38
|
}
|
|
35
|
-
}).listen(port,
|
|
39
|
+
}).listen(port, () => {
|
|
36
40
|
t.pass('listening')
|
|
37
41
|
t.end()
|
|
38
42
|
})
|
|
39
43
|
})
|
|
40
44
|
|
|
41
|
-
|
|
45
|
+
tearDown(() => {
|
|
42
46
|
server.close()
|
|
43
47
|
})
|
|
44
48
|
|
|
45
|
-
|
|
49
|
+
test('simple request', (t) => {
|
|
46
50
|
cacheControl = null
|
|
47
|
-
req('/test/st.js',
|
|
48
|
-
t.
|
|
51
|
+
req('/test/st.js', (er, res, body) => {
|
|
52
|
+
t.error(er)
|
|
49
53
|
t.equal(res.headers['cache-control'], 'public, max-age=600')
|
|
50
54
|
t.end()
|
|
51
55
|
})
|
|
52
56
|
})
|
|
53
57
|
|
|
54
|
-
|
|
58
|
+
test('pre-set cache-control', (t) => {
|
|
55
59
|
cacheControl = 'I\'m so excited, and I just can\'t hide it'
|
|
56
|
-
req('/test/st.js',
|
|
57
|
-
t.
|
|
60
|
+
req('/test/st.js', (er, res, body) => {
|
|
61
|
+
t.error(er)
|
|
58
62
|
t.equal(res.headers['cache-control'], cacheControl)
|
|
59
63
|
t.end()
|
|
60
64
|
})
|
package/.npmignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
node_modules
|