serve-content
serve-content based on file name extensions and serving jade and stylus files
based on serve-static
All in serve-static documentation is working here. But serve-content add some mandatory parameters to indicate which are the allowed extensions:
allowedExts
allowedExts is a white list of extensions names for serve.
allowAllExts
allowAllExts is a boolean. True means that all extensions are allowed. It can be used with excludeExts
.
excludeExts
allowedExts is a black list with ignorings extensions.
example
var connect = require('connect')
var extensionServeStatic = require('serve-content')
var app = connect()
// Serve up all folders for images
app.use(serveContent('/', {
extensions: ['html', 'htm'],
index: 'index.html',
allowedExts: ['', 'html', 'htm', 'png', 'jpg', 'jpeg', 'gif']
})
// Listen
app.listen(3000)
default extensions
For use the serve-static extensions parameter you must include de empty string ('') in the staticExtension list (as you see in the example).
mime types
serve-content also search the extension in the mime types. If you need to add a non standard extension you can add it in the mime field
var connect = require('connect')
var extensionServeStatic = require('serve-content')
var mime = extensionServeStatic.mime;
mime.types.specialimage = 'image/special';
var app = connect()
// Serve up all folders for images
app.use(serveContent('/', {
extensions: ['html', 'htm'],
index: 'index.html',
allowedExts: ['', 'html', 'htm', 'png', 'jpg', 'jpeg', 'gif', 'specialimage']
})
// Listen
app.listen(3000)