Comparing version 3.3.1 to 4.0.0
@@ -0,1 +1,14 @@ | ||
2019/04/05 Version 4.0.0 | ||
- Drop testing/support for nodes 4 and 5, test nodes 9, 10 and 11 | ||
- Fix parsing of CORS options | ||
- Upgrade mime module to v2, use charset module for charset detection | ||
- Remove ability to set mime types with a .types file | ||
- Add ability to override mime type and charset lookup with globally-set | ||
functions | ||
- Removes default charset of utf8 - if you need this, try using a custom | ||
charset lookup function | ||
- Move bin behavior from inside ./lib/ecstatic.js into ./lib/bin.js - see issue | ||
#226 for more information | ||
- Update modules and fix linting | ||
2019/02/10 Version 3.3.1 | ||
@@ -2,0 +15,0 @@ - Publish via linux to hopefully fix #238 |
@@ -70,1 +70,2 @@ General format is: contributor, github handle, email. In some cases, the | ||
* Jade Michael Thornton @thornjad <jade@jmthorton.net> | ||
* @BigBlueHat |
@@ -8,3 +8,3 @@ #! /usr/bin/env node | ||
const url = require('url'); | ||
const mime = require('mime'); | ||
const mime = require('./ecstatic/mime'); | ||
const urlJoin = require('url-join'); | ||
@@ -43,3 +43,3 @@ const showDir = require('./ecstatic/show-dir'); | ||
.some(el => ['*', 'compress', 'gzip', 'deflate'].indexOf(el.trim()) !== -1) | ||
; | ||
; | ||
} | ||
@@ -52,4 +52,4 @@ | ||
headers['accept-encoding'] | ||
.split(',') | ||
.some(el => ['*', 'br'].indexOf(el.trim()) !== -1) | ||
.split(',') | ||
.some(el => ['*', 'br'].indexOf(el.trim()) !== -1) | ||
; | ||
@@ -60,3 +60,3 @@ } | ||
const stream = fs.createReadStream(gzipped, { start: 0, end: 1 }); | ||
let buffer = Buffer(''); | ||
let buffer = Buffer.from(''); | ||
let hasBeenCalled = false; | ||
@@ -117,3 +117,2 @@ | ||
// Support hashes and .types files in mimeTypes @since 0.8 | ||
if (opts.mimeTypes) { | ||
@@ -126,7 +125,8 @@ try { | ||
} | ||
if (typeof opts.mimeTypes === 'string') { | ||
mime.load(opts.mimeTypes); | ||
} else if (typeof opts.mimeTypes === 'object') { | ||
if (typeof opts.mimeTypes === 'object') { | ||
mime.define(opts.mimeTypes); | ||
} | ||
if (typeof opts.mimeTypes === 'function') { | ||
mime.setCustomGetType(opts.mimeTypes); | ||
} | ||
} | ||
@@ -253,3 +253,4 @@ | ||
const defaultType = opts.contentType || 'application/octet-stream'; | ||
let contentType = mime.lookup(file, defaultType); | ||
let contentType = mime.getType(file, defaultType); | ||
let charSet; | ||
@@ -262,3 +263,3 @@ const range = (req.headers && req.headers.range); | ||
if (contentType) { | ||
charSet = mime.charsets.lookup(contentType, 'utf-8'); | ||
charSet = mime.lookupCharset(contentType); | ||
if (charSet) { | ||
@@ -272,7 +273,7 @@ contentType += `; charset=${charSet}`; | ||
// strip gz ending and lookup mime type | ||
contentType = mime.lookup(path.basename(file, '.gz'), defaultType); | ||
contentType = mime.getType(path.basename(file, '.gz'), defaultType); | ||
} else if (file === brotliFile) { // is .br picked up | ||
res.setHeader('Content-Encoding', 'br'); | ||
// strip br ending and lookup mime type | ||
contentType = mime.lookup(path.basename(file, '.br'), defaultType); | ||
contentType = mime.getType(path.basename(file, '.br'), defaultType); | ||
} | ||
@@ -477,33 +478,2 @@ | ||
ecstatic.showDir = showDir; | ||
if (!module.parent) { | ||
/* eslint-disable global-require */ | ||
/* eslint-disable no-console */ | ||
const defaults = require('./ecstatic/defaults.json'); | ||
const http = require('http'); | ||
const minimist = require('minimist'); | ||
const aliases = require('./ecstatic/aliases.json'); | ||
const opts = minimist(process.argv.slice(2), { | ||
alias: aliases, | ||
default: defaults, | ||
boolean: Object.keys(defaults).filter( | ||
key => typeof defaults[key] === 'boolean' | ||
), | ||
}); | ||
const envPORT = parseInt(process.env.PORT, 10); | ||
const port = envPORT > 1024 && envPORT <= 65536 ? envPORT : opts.port || opts.p || 8000; | ||
const dir = opts.root || opts._[0] || process.cwd(); | ||
if (opts.help || opts.h) { | ||
console.error('usage: ecstatic [dir] {options} --port PORT'); | ||
console.error('see https://npm.im/ecstatic for more docs'); | ||
} else { | ||
http.createServer(ecstatic(dir, opts)) | ||
.listen(port, () => { | ||
console.log(`ecstatic serving ${dir} at http://0.0.0.0:${port}`); | ||
}) | ||
; | ||
} | ||
} | ||
ecstatic.mime = mime; |
@@ -122,3 +122,3 @@ 'use strict'; | ||
aliases.cors.forEach((k) => { | ||
if (isDeclared(k) && k) { | ||
if (isDeclared(k) && opts[k]) { | ||
handleOptionsMethod = true; | ||
@@ -125,0 +125,0 @@ headers['Access-Control-Allow-Origin'] = '*'; |
@@ -127,7 +127,8 @@ 'use strict'; | ||
html += '</table>\n'; | ||
html += `<br><address>Node.js ${ | ||
process.version | ||
}/ <a href="https://github.com/jfhbrook/node-ecstatic">ecstatic</a> ` + | ||
`server running @ ${ | ||
he.encode(req.headers.host || '')}</address>\n` + | ||
html += `<br><address>Node.js | ||
${process.version} | ||
/ <a href="https://github.com/jfhbrook/node-ecstatic">ecstatic</a> ` + | ||
`server running @ | ||
${he.encode(req.headers.host || '')} | ||
</address>\n` + | ||
'</body></html>' | ||
@@ -134,0 +135,0 @@ ; |
@@ -5,3 +5,3 @@ { | ||
"description": "A simple static file server middleware", | ||
"version": "3.3.1", | ||
"version": "4.0.0", | ||
"homepage": "https://github.com/jfhbrook/node-ecstatic", | ||
@@ -19,3 +19,3 @@ "repository": { | ||
}, | ||
"bin": "./lib/ecstatic.js", | ||
"bin": "./lib/bin.js", | ||
"keywords": [ | ||
@@ -30,10 +30,11 @@ "static", | ||
"dependencies": { | ||
"charset": "^1.0.1", | ||
"he": "^1.1.1", | ||
"mime": "^1.6.0", | ||
"mime": "^2.4.1", | ||
"minimist": "^1.1.0", | ||
"url-join": "^2.0.5" | ||
"url-join": "^4.0.0" | ||
}, | ||
"devDependencies": { | ||
"eol": "^0.9.1", | ||
"eslint": "^3.19.0", | ||
"eslint": "^4.5.0", | ||
"eslint-config-airbnb-base": "^11.3.2", | ||
@@ -44,5 +45,5 @@ "eslint-plugin-import": "^2.14.0", | ||
"request": "^2.88.0", | ||
"tap": "^12.0.1" | ||
"tap": "^12.6.1" | ||
}, | ||
"license": "MIT" | ||
} |
@@ -239,8 +239,15 @@ # Ecstatic [![build status](https://secure.travis-ci.org/jfhbrook/node-ecstatic.png)](http://travis-ci.org/jfhbrook/node-ecstatic) [![codecov.io](https://codecov.io/github/jfhbrook/node-ecstatic/coverage.svg?branch=master)](https://codecov.io/github/jfhbrook/node-ecstatic?branch=master) | ||
Add new or override one or more mime-types. This affects the HTTP Content-Type | ||
header. Can either be a path to a | ||
[`.types`](http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types) | ||
file or an object hash of type(s). | ||
header. May be either an object hash of type(s), *or* a function | ||
`(file, defaultValue) => 'some/mimetype'`. Naturally, only the object hash | ||
works on the command line. | ||
ecstatic({ mimeTypes: { 'mime-type': ['file_extension', 'file_extension'] } }) | ||
ecstatic({ mimeTypes: { 'some/mimetype': ['file_extension', 'file_extension'] } }) | ||
It's important to note that any changes to mime handling are **global**, since | ||
the `mime` module appears to be poorly behaved outside of a global singleton | ||
context. For clarity you may prefer to call `require('ecstatic').mime.define` | ||
or `require('ecstatic').setCustomGetType` directly and skip using this option, | ||
particularly in cases where you're using multiple instances of ecstatic's | ||
middleware. **You've been warned!** | ||
### `opts.handleError` | ||
@@ -284,2 +291,40 @@ | ||
### ecstatic.mime.define(mappings); | ||
This defines new mappings for the mime singleton, as specified in the main | ||
docs for the ecstatic middleware. Calling this directly should make global | ||
mutation more clear than setting the options when instantiating the middleware, | ||
and is recommended if you're using more than one middlware instance. | ||
### ecstatic.mime.setCustomGetType(fn); | ||
This sets a global custom function for getting the mime type for a filename. | ||
If this function returns a falsey value, getType will fall back to the mime | ||
module's handling. Calling this directly should make global mutation more clear | ||
than setting the options when instantiating the middleware, and is recommended | ||
if you're using more than one middleware instance. | ||
### ecstatic.mime.getType(filename, defaultValue); | ||
This will return the mimetype for a filename, first using any function supplied | ||
with `ecstatic.mime.setCustomGetType`, then trying `require('mime').getType`, | ||
then falling back to defaultValue. Generally you don't want to use this | ||
directly. | ||
### ecstatic.mime.setCustomLookupCharset(fn); | ||
This sets a global custom function for getting the charset for a mime type. | ||
If this function returns a falsey value, lookupCharset will fall back on the | ||
charset module's handling. Calling this directly should make global mutation | ||
more clear than setting the options when instantiating the middleware, and is | ||
recommended if you're using more than one middleware instance. | ||
### ecstatic.mime.lookupCharset(mimeType); | ||
This will look up the charset for the supplied mime type, first using any | ||
function supplied with `ecstatic.mime.setCustomLookupCharset`, then trying | ||
`require('charset')(mimeType)`. Generally you | ||
don't want to use this directly. | ||
# Tests: | ||
@@ -286,0 +331,0 @@ |
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
316658
29
1320
345
5
+ Addedcharset@^1.0.1
+ Addedcharset@1.0.1(transitive)
+ Addedmime@2.6.0(transitive)
+ Addedurl-join@4.0.1(transitive)
- Removedmime@1.6.0(transitive)
- Removedurl-join@2.0.5(transitive)
Updatedmime@^2.4.1
Updatedurl-join@^4.0.0