https://github.com/thinkjs/think-resource
Resource for ThinkJS 3.x
https://github.com/thinkjs/think-resource
middleware resource-manager static thinkjs3
Last synced: 10 months ago
JSON representation
Resource for ThinkJS 3.x
- Host: GitHub
- URL: https://github.com/thinkjs/think-resource
- Owner: thinkjs
- License: mit
- Created: 2017-04-10T07:21:21.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-07-30T05:37:54.000Z (almost 9 years ago)
- Last Synced: 2025-06-26T11:18:06.822Z (11 months ago)
- Topics: middleware, resource-manager, static, thinkjs3
- Language: JavaScript
- Size: 25.4 KB
- Stars: 4
- Watchers: 12
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# think-resource
Resource for ThinkJS 3.x
[](https://www.npmjs.com/package/think-resource)
[](https://travis-ci.org/thinkjs/think-resource)
[](https://coveralls.io/github/thinkjs/think-resource?branch=master)
think-resource is an static-file handler for ThinkJS 3.x.
## Installation
```
$ npm install think-resource
```
##
## API
Modify `src/config/middleware.js`
```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 is `index.html`.
- `hidden`: Allow transfer of hidden files. default is `false`.
- `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 is `false`.
- `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 is `false`.
- `extensions`: Try to match extensions from passed array to search for file when no extension is sufficed in URL. First found is served. default is `false`.
- `maxage`: Function to set custom headers on response. Browser cache max-age in milliseconds, default is `0`.
- `publicPath`: Public path for route-match. default is `/`.
- `setHeaders`: Function to set custom headers on response. default is `false`. usage: `setHeaders: function(res, path, stats){}`
- `notFoundNext`: If it can't find target file, will continue excuting `next` function. default is `false`.
## Contributing
Contributions welcome!
## License
[Mit](https://github.com/thinkjs/think-resource/blob/master/LICENSE)