Skip to content

Commit 62194ad

Browse files
committed
build: minor code cleanup
1 parent 974319e commit 62194ad

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

index.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,19 @@ var url = require('url');
2424
* @api public
2525
*/
2626

27-
exports = module.exports = function(root, options){
28-
// root required
29-
if (!root) throw new TypeError('root path required');
27+
exports = module.exports = function serveStatic(root, options) {
28+
if (!root) {
29+
throw new TypeError('root path required')
30+
}
3031

3132
// copy options object
3233
options = merge({}, options)
3334

3435
// resolve root to absolute
35-
root = resolve(root);
36+
root = resolve(root)
3637

3738
// default redirect
38-
var redirect = false !== options.redirect;
39+
var redirect = options.redirect !== false
3940

4041
// headers listener
4142
var setHeaders = options.setHeaders
@@ -46,15 +47,17 @@ exports = module.exports = function(root, options){
4647
}
4748

4849
// setup options for send
49-
options.maxage = options.maxage || options.maxAge || 0;
50-
options.root = root;
50+
options.maxage = options.maxage || options.maxAge || 0
51+
options.root = root
5152

52-
return function staticMiddleware(req, res, next) {
53-
if ('GET' != req.method && 'HEAD' != req.method) return next();
53+
return function serveStatic(req, res, next) {
54+
if (req.method !== 'GET' && req.method !== 'HEAD') {
55+
return next()
56+
}
5457

5558
var opts = merge({}, options)
56-
var originalUrl = parseurl.original(req);
57-
var path = parseurl(req).pathname;
59+
var originalUrl = parseurl.original(req)
60+
var path = parseurl(req).pathname
5861

5962
if (path === '/' && originalUrl.pathname[originalUrl.pathname.length - 1] !== '/') {
6063
// make sure redirect occurs at mount
@@ -93,8 +96,8 @@ exports = module.exports = function(root, options){
9396

9497
// pipe
9598
stream.pipe(res)
96-
};
97-
};
99+
}
100+
}
98101

99102
/**
100103
* Expose mime module.
@@ -103,4 +106,4 @@ exports = module.exports = function(root, options){
103106
* reference to the "mime" module in the npm registry.
104107
*/
105108

106-
exports.mime = send.mime;
109+
exports.mime = send.mime

0 commit comments

Comments
 (0)