use serve-static for static middleware
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Jonathan Ong · committed by Jonathan Ong · parent f1315b9 · Browse files · 3 files·+2 added−88 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+2 added−88 removed
- other:+2 added−88 removed
Provenance
- Commit
6ec1904- Tree
cba2743- Author
Jonathan Ong <jonathanrichardong@gmail.com>- Committer
Jonathan Ong <jonathanrichardong@gmail.com>- Parent
f1315b9
3 files changed+2 added−88 removed
deleted:lib/middleware/static.js-87 removed
1-/*!2- * Connect - static3- * Copyright(c) 2010 Sencha Inc.4- * Copyright(c) 2011 TJ Holowaychuk5- * MIT Licensed6- */7-8-/**9- * Module dependencies.10- */11-12-var send = require('send')13- , utils = require('../utils')14- , parse = utils.parseUrl15- , url = require('url');16-17-/**18- * Static:19- *20- * Static file server with the given `root` path.21- *22- * Examples:23- *24- * var oneDay = 86400000;25- *26- * connect()27- * .use(connect.static(__dirname + '/public'))28- *29- * connect()30- * .use(connect.static(__dirname + '/public', { maxAge: oneDay }))31- *32- * Options:33- *34- * - `maxAge` Browser cache maxAge in milliseconds. defaults to 035- * - `hidden` Allow transfer of hidden files. defaults to false36- * - `redirect` Redirect to trailing "/" when the pathname is a dir. defaults to true37- * - `index` Default file name, defaults to 'index.html'38- *39- * @param {String} root40- * @param {Object} options41- * @return {Function}42- * @api public43- */44-45-exports = module.exports = function(root, options){46- options = options || {};47-48- // root required49- if (!root) throw new Error('static() root path required');50-51- // default redirect52- var redirect = false !== options.redirect;53-54- return function staticMiddleware(req, res, next) {55- if ('GET' != req.method && 'HEAD' != req.method) return next();56- var originalUrl = url.parse(req.originalUrl);57- var path = parse(req).pathname;58-59- if (path == '/' && originalUrl.pathname[originalUrl.pathname.length - 1] != '/') {60- return directory();61- }62-63- function directory() {64- if (!redirect) return next();65- var target;66- originalUrl.pathname += '/';67- target = url.format(originalUrl);68- res.statusCode = 303;69- res.setHeader('Location', target);70- res.end('Redirecting to ' + utils.escape(target));71- }72-73- function error(err) {74- if (404 == err.status) return next();75- next(err);76- }77-78- send(req, path)79- .maxage(options.maxAge || 0)80- .root(root)81- .index(options.index || 'index.html')82- .hidden(options.hidden)83- .on('error', error)84- .on('directory', directory)85- .pipe(res);86- };87-};modified:lib/express.js+1 added-1 removed
60 unmodified lines61626364656560 unmodified lines/** * Expose middleware */
exports.static = require('./middleware/static');exports.static = require('serve-static');modified:package.json+1 added
33 unmodified lines34353637383940414236 unmodified lines33 unmodified lines "merge-descriptors": "0.0.2", "utils-merge": "1.0.0", "escape-html": "1.0.1", "qs": "0.6.6", "serve-static": "1.0.1", "debug": ">= 0.7.3 < 1" }, "devDependencies": { "ejs": "~0.8.4",36 unmodified lines