Socket
Socket
Sign inDemoInstall

ecstatic

Package Overview
Dependencies
Maintainers
2
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ecstatic - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

5

CHANGELOG.md

@@ -0,1 +1,6 @@

2015/10/01 Version 1.1.0
- Adds support for responding to OPTIONS headers
- Adds support for setting custom headers
- Adds cors convenience setting
2015/09/22 Version 1.0.1

@@ -2,0 +7,0 @@ - Use encodeURIComponent when creating links in showdir

11

lib/ecstatic.js

@@ -29,4 +29,6 @@ #! /usr/bin/env node

handleError = opts.handleError,
headers = opts.headers,
serverHeader = opts.serverHeader,
weakEtags = opts.weakEtags;
weakEtags = opts.weakEtags,
handleOptionsMethod = opts.handleOptionsMethod;

@@ -77,3 +79,10 @@ opts.root = dir;

}
Object.keys(headers).forEach(function (key) {
res.setHeader(key, headers[key])
})
if (req.method === 'OPTIONS' && handleOptionsMethod) {
return res.end();
}
// TODO: This check is broken, which causes the 403 on the

@@ -80,0 +89,0 @@ // expected 404.

@@ -13,2 +13,3 @@ // This is so you can have options aliasing and defaults in one place.

handleError = true,
headers = {},
serverHeader = true,

@@ -18,3 +19,4 @@ contentType = 'application/octet-stream',

weakEtags = false,
weakCompare = false;
weakCompare = false,
handleOptionsMethod = false;

@@ -95,2 +97,36 @@ function isDeclared(k) {

[
'cors',
'CORS'
].forEach(function(k) {
if (isDeclared(k) && k) {
handleOptionsMethod = true;
headers['Access-Control-Allow-Origin'] = '*';
headers['Access-Control-Allow-Headers'] = 'Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since';
}
});
[
'H',
'header',
'headers'
].forEach(function (k) {
if (!isDeclared(k)) return;
if (Array.isArray(opts[k])) {
opts[k].forEach(setHeader);
}
else if (opts[k] && typeof opts[k] === 'object') {
Object.keys(opts[k]).forEach(function (key) {
headers[key] = opts[k][key];
});
}
else setHeader(opts[k]);
function setHeader (str) {
var m = /^(.+?)\s*:\s*(.*)$/.exec(str)
if (!m) headers[str] = true
else headers[m[1]] = m[2]
}
});
[
'serverHeader',

@@ -155,2 +191,13 @@ 'serverheader',

});
[
'handleOptionsMethod',
'handleoptionsmethod',
'handle-options-method'
].some(function (k) {
if (isDeclared(k)) {
handleOptionsMethod = opts[k];
return true;
}
});
}

@@ -168,2 +215,3 @@

handleError: handleError,
headers: headers,
serverHeader: serverHeader,

@@ -173,4 +221,5 @@ contentType: contentType,

weakEtags: weakEtags,
weakCompare: weakCompare
weakCompare: weakCompare,
handleOptionsMethod: handleOptionsMethod
};
};

2

package.json

@@ -5,3 +5,3 @@ {

"description": "A simple static file server middleware that works with both Express and Flatiron",
"version": "1.0.1",
"version": "1.1.0",
"homepage": "https://github.com/jfhbrook/node-ecstatic",

@@ -8,0 +8,0 @@ "repository": {

@@ -66,14 +66,16 @@ # Ecstatic [![build status](https://secure.travis-ci.org/jfhbrook/node-ecstatic.png)](http://travis-ci.org/jfhbrook/node-ecstatic)

var opts = {
root : __dirname + '/public',
baseDir : '/',
cache : 3600,
showDir : true,
autoIndex : false,
humanReadable : true,
si : false,
defaultExt : 'html',
gzip : false,
serverHeader : true,
contentType : 'application/octet-stream',
mimeTypes : undefined
root : __dirname + '/public',
baseDir : '/',
cache : 3600,
showDir : true,
autoIndex : false,
humanReadable : true,
headers : {},
si : false,
defaultExt : 'html',
gzip : false,
serverHeader : true,
contentType : 'application/octet-stream',
mimeTypes : undefined,
handleOptionsMethod: false
}

@@ -110,2 +112,15 @@ ```

### `opts.headers`
Set headers on every response. `opts.headers` can be an object mapping string
header names to string header values, a colon (:) separated string, or an array
of colon separated strings.
`opts.H` and `opts.header` are aliased to `opts.headers` so that you can use
`-H` and `--header` options to set headers on the command-line like curl:
``` sh
$ ecstatic ./public -p 5000 -H 'Access-Control-Allow-Origin: *'
```
### `opts.si`

@@ -166,2 +181,12 @@

### `opts.handleOptionsMethod`
Set handleOptionsMethod to true in order to respond to 'OPTIONS' calls with any standard/set headers. Defaults to **false**. Useful for hacking up CORS support.
### `opts.cors`
This is a **convenience** setting which turns on `handleOptionsMethod` and sets the headers **Access-Control-Allow-Origin: \*** and **Access-Control-Allow-Headers: Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since**. This *should* be enough to quickly make cross-origin resource sharing work between development APIs. More advanced usage can come either from overriding these headers with the headers argument, or by using the `handleOptionsMethod` flag and then setting headers "manually." Alternately, just do it in your app using separate middlewares/abstractions.
Defaults to **false**.
## middleware(req, res, next);

@@ -168,0 +193,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc