1.0.3 • Published 8 years ago
think-resource v1.0.3
think-resource
Resource for ThinkJS 3.x
think-resource is an static-file handler for ThinkJS 3.x.
Installation
$ npm install think-resourceAPI
Modify src/config/middleware.js
const resource = require('think-resource')
module.exports = [
{
handle: resource,
options: {
root: '.',
publicPath: '/static',
index: 'index.html',
hidden: false,
format: true,
gzip: false,
extensions: ['.txt'],
maxage: 0,
setHeaders: function(res, path, stats) {
...
},
notFoundNext: false
}
}
]Options
root: Root directory to restrict file access,require.index: Default file name, default isindex.html.hidden: Allow transfer of hidden files. default isfalse.format: If not false (defaults to true), format the path to serve static file servers and not require a trailing slash for directories, so that you can do both /directory and /directory/, default isfalse.gzip: Try to serve the gzipped version of a file automatically when gzip is supported by a client and if the requested file with .gz extension exists. default isfalse.extensions: Try to match extensions from passed array to search for file when no extension is sufficed in URL. First found is served. default isfalse.maxage: Function to set custom headers on response. Browser cache max-age in milliseconds, default is0.publicPath: Public path for route-match. default is/.setHeaders: Function to set custom headers on response. default isfalse. usage:setHeaders: function(res, path, stats){}notFoundNext: If it can't find target file, will continue excutingnextfunction. default isfalse.
Contributing
Contributions welcome!