Comparing version 2.0.0 to 3.0.0
#!/usr/bin/env node | ||
const st = require('../st.js') | ||
const http = require('http') | ||
const { STATUS_CODES } = http | ||
let port = +(process.env.PORT || 1337) | ||
@@ -183,3 +184,3 @@ let host | ||
s.statusCode = 404 | ||
s.end('not found') | ||
s.end(STATUS_CODES[s.statusCode]) | ||
}).listen(port, host, function () { | ||
@@ -186,0 +187,0 @@ const addr = this.address() |
{ | ||
"name": "st", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"description": "A module for serving static files. Does etags, caching, etc.", | ||
@@ -9,5 +9,5 @@ "main": "st.js", | ||
"async-cache": "^1.1.0", | ||
"bl": "^4.0.0", | ||
"fd": "~0.0.2", | ||
"mime": "^2.4.4", | ||
"bl": "^5.0.0", | ||
"fd": "~0.0.3", | ||
"mime": "^2.5.2", | ||
"negotiator": "~0.6.2" | ||
@@ -19,10 +19,10 @@ }, | ||
"devDependencies": { | ||
"request": "^2.88.0", | ||
"rimraf": "^3.0.0", | ||
"standard": "^14.3.1", | ||
"tap": "^14.9.2" | ||
"request": "^2.88.2", | ||
"rimraf": "^3.0.2", | ||
"standard": "^16.0.3", | ||
"tap": "^15.0.9" | ||
}, | ||
"scripts": { | ||
"lint": "standard", | ||
"test": "npm run lint && tap test/*.js test/cli/*-test.js" | ||
"test": "npm run lint && tap test/*.js test/cli/*-test.js --no-coverage" | ||
}, | ||
@@ -29,0 +29,0 @@ "repository": { |
32
st.js
@@ -16,2 +16,3 @@ const mime = require('mime') | ||
const bl = require('bl') | ||
const { STATUS_CODES } = http | ||
@@ -118,4 +119,6 @@ const defaultCacheOptions = { | ||
this.path = opt.path | ||
this._index = opt.index === false ? false | ||
: typeof opt.index === 'string' ? opt.index | ||
this._index = opt.index === false | ||
? false | ||
: typeof opt.index === 'string' | ||
? opt.index | ||
: true | ||
@@ -256,3 +259,3 @@ this.fdman = FD() | ||
res.statusCode = 403 | ||
res.end('Forbidden') | ||
res.end(STATUS_CODES[res.statusCode]) | ||
return true | ||
@@ -353,5 +356,8 @@ } | ||
error (er, res) { | ||
res.statusCode = typeof er === 'number' ? er | ||
: er.code === 'ENOENT' || er.code === 'EISDIR' ? 404 | ||
: er.code === 'EPERM' || er.code === 'EACCES' ? 403 | ||
res.statusCode = typeof er === 'number' | ||
? er | ||
: er.code === 'ENOENT' || er.code === 'EISDIR' | ||
? 404 | ||
: er.code === 'EPERM' || er.code === 'EACCES' | ||
? 403 | ||
: 500 | ||
@@ -365,3 +371,3 @@ | ||
res.setHeader('content-type', 'text/plain') | ||
res.end(http.STATUS_CODES[res.statusCode] + '\n') | ||
res.end(STATUS_CODES[res.statusCode] + '\n') | ||
} | ||
@@ -567,6 +573,10 @@ | ||
}).sort((a, b) => { | ||
return a[2] === '-' && b[2] !== '-' ? -1 // dirs first | ||
: a[2] !== '-' && b[2] === '-' ? 1 | ||
: a[0].toLowerCase() < b[0].toLowerCase() ? -1 // then alpha | ||
: a[0].toLowerCase() > b[0].toLowerCase() ? 1 | ||
return a[2] === '-' && b[2] !== '-' // dirs first | ||
? -1 | ||
: a[2] !== '-' && b[2] === '-' | ||
? 1 | ||
: a[0].toLowerCase() < b[0].toLowerCase() // then alpha | ||
? -1 | ||
: a[0].toLowerCase() > b[0].toLowerCase() | ||
? 1 | ||
: 0 | ||
@@ -573,0 +583,0 @@ }).forEach((line) => { |
@@ -7,3 +7,3 @@ const { test } = require('tap') | ||
req('/st.js', (er, res, body) => { | ||
t.ifError(er) && | ||
t.error(er) && | ||
t.equal(res.statusCode, 200) && | ||
@@ -13,3 +13,3 @@ t.equal(body.toString(), stExpect) | ||
}, (er, stdout, stderr) => { | ||
t.ifError(er) | ||
t.error(er) | ||
t.match(stdout, /^listening at http:\/\/(\[::\]|0\.0\.0\.0):[0-9]+\n$/) | ||
@@ -24,3 +24,3 @@ t.equal(stderr, '') | ||
req('/st.js', (er, res, body) => { | ||
t.ifError(er) && | ||
t.error(er) && | ||
t.equal(res.statusCode, 200) && | ||
@@ -30,3 +30,3 @@ t.equal(body.toString(), stExpect) | ||
}, (er, stdout, stderr) => { | ||
t.ifError(er) | ||
t.error(er) | ||
t.match(stdout, /^listening at http:\/\/localhost:[0-9]+\n$/) | ||
@@ -33,0 +33,0 @@ t.equal(stderr, '') |
@@ -47,3 +47,3 @@ const os = require('os') | ||
}, (err, stdout, stderr) => { | ||
t.ifError(err) | ||
t.error(err) | ||
t.equal(stderr, '') | ||
@@ -63,3 +63,3 @@ if (addr) { | ||
if (canConnect) { | ||
t.ifError(er, url) && t.equal(res.statusCode, 200, url) | ||
t.error(er, url) && t.equal(res.statusCode, 200, url) | ||
} else { | ||
@@ -66,0 +66,0 @@ t.ok(er, url) |
@@ -5,3 +5,3 @@ const path = require('path') | ||
const request = require('request') | ||
const { test, tearDown } = require('tap') | ||
const { test, teardown } = require('tap') | ||
@@ -60,3 +60,3 @@ const st = require('../st.js') | ||
tearDown(() => { | ||
teardown(() => { | ||
server.close() | ||
@@ -63,0 +63,0 @@ }) |
const path = require('path') | ||
const http = require('http') | ||
const request = require('request') | ||
const { test, tearDown } = require('tap') | ||
const { test, teardown } = require('tap') | ||
@@ -40,3 +40,3 @@ const st = require('../st.js') | ||
tearDown(() => { | ||
teardown(() => { | ||
server.close() | ||
@@ -43,0 +43,0 @@ }) |
@@ -28,3 +28,3 @@ global.options = { | ||
t.ok(body, 'returned a body') | ||
t.notEqual(body.toString(), stExpect, 'gzipped string') | ||
t.not(body.toString(), stExpect, 'gzipped string') | ||
@@ -31,0 +31,0 @@ zlib.gunzip(body, (er, body) => { |
const st = require('../st.js') | ||
const { test, tearDown } = require('tap') | ||
const { test, teardown } = require('tap') | ||
const path = require('path') | ||
@@ -45,3 +45,3 @@ const http = require('http') | ||
tearDown(() => { | ||
teardown(() => { | ||
server.close() | ||
@@ -48,0 +48,0 @@ }) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
66551
37
1763
7
+ Addedbl@5.1.0(transitive)
+ Addedbuffer@6.0.3(transitive)
- Removedbl@4.1.0(transitive)
- Removedbuffer@5.7.1(transitive)
Updatedbl@^5.0.0
Updatedfd@~0.0.3
Updatedmime@^2.5.2