{"_id":"@cgfamily/think-resource","name":"@cgfamily/think-resource","dist-tags":{"latest":"1.0.3"},"versions":{"1.0.3":{"name":"@cgfamily/think-resource","version":"1.0.3","description":"Resource for ThinkJS 3.x ","main":"index.js","scripts":{"test":"eslint index.js && nyc ava test/index.js && nyc report --reporter=html"},"repository":{"type":"git","url":"git+https://github.com/thinkjs/think-resource.git"},"keywords":["resource","thinkjs","node","static"],"author":{"name":"xiamingxing"},"engines":{"node":">=6.0.0"},"license":"MIT","bugs":{"url":"https://github.com/thinkjs/think-resource/issues"},"homepage":"https://github.com/thinkjs/think-resource#readme","dependencies":{"debug":"^2.6.3","koa-send":"3.3.0","think-helper":"1.1.4"},"devDependencies":{"ava":"^0.19.1","babel-eslint":"^7.2.1","babel-preset-think-node":"^1.0.1","coveralls":"^2.13.0","eslint":"^3.19.0","eslint-config-think":"^1.0.1","koa":"^2.2.0","nyc":"^10.2.0","supertest":"^3.0.0","think-helper":"1.1.4"},"ava":{"require":["babel-core/register"],"babel":"inherit"},"babel":{"presets":["think-node"]},"gitHead":"1bd919ac6f678be27e4d735baee59ebb0881e938","_id":"@cgfamily/think-resource@1.0.3","_nodeVersion":"14.18.2","_npmVersion":"6.14.15","dist":{"integrity":"sha512-hXSu/CGHfzo3Xa8HGiDtTiWnTUdb60wevdtKcDusQCIeAahuHcX8sJigM9c0m6x3yPqBgdL4R0UsBX6qDYri5g==","shasum":"5a2478114b865412be517f47d77685c08ca27c87","tarball":"https://registry.npmjs.org/@cgfamily/think-resource/-/think-resource-1.0.3.tgz","fileCount":7,"unpackedSize":10687,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDQZokApy0oQBuZHU2Bbgmnsg+oYpy3Isj5YCgWkvHt8AIgQ3HccU778117SwY08vU9vI59sIVFwo7wCr2FnIrBVCI="}]},"_npmUser":{"name":"cgfamily","email":"18751290129@163.com"},"directories":{},"maintainers":[{"name":"cgfamily","email":"18751290129@163.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/think-resource_1.0.3_1705480744767_0.7698816282567433"},"_hasShrinkwrap":false}},"time":{"created":"2024-01-17T08:39:04.669Z","1.0.3":"2024-01-17T08:39:04.900Z","modified":"2024-01-17T08:39:05.115Z"},"maintainers":[{"name":"cgfamily","email":"18751290129@163.com"}],"description":"Resource for ThinkJS 3.x ","homepage":"https://github.com/thinkjs/think-resource#readme","keywords":["resource","thinkjs","node","static"],"repository":{"type":"git","url":"git+https://github.com/thinkjs/think-resource.git"},"author":{"name":"xiamingxing"},"bugs":{"url":"https://github.com/thinkjs/think-resource/issues"},"license":"MIT","readme":"# think-resource\r\nResource for ThinkJS 3.x\r\n\r\n[![npm](https://img.shields.io/npm/v/think-resource.svg)](https://www.npmjs.com/package/think-resource)\r\n[![Build Status](https://travis-ci.org/thinkjs/think-resource.svg?branch=master)](https://travis-ci.org/thinkjs/think-resource)\r\n[![Coverage Status](https://coveralls.io/repos/github/thinkjs/think-resource/badge.svg?branch=master)](https://coveralls.io/github/thinkjs/think-resource?branch=master)\r\n\r\nthink-resource is an static-file handler for ThinkJS 3.x. \r\n\r\n## Installation\r\n\r\n```\r\n$  npm install think-resource\r\n```\r\n\r\n## \r\n\r\n## API\r\n\r\nModify `src/config/middleware.js`\r\n\r\n```js\r\nconst resource = require('think-resource')\r\n\r\nmodule.exports = [\r\n  { \r\n      handle: resource,\r\n      options: {\r\n           root: '.',\r\n           publicPath: '/static',\r\n           index: 'index.html',\r\n           hidden: false,\r\n           format: true,\r\n           gzip: false,\r\n           extensions: ['.txt'],\r\n           maxage: 0,\r\n           setHeaders: function(res, path, stats) {\r\n              ...\r\n           },\r\n           notFoundNext: false\r\n      }\r\n  }\r\n]\r\n```\r\n\r\n### Options\r\n\r\n- `root`:  Root directory to restrict file access， `require`.\r\n- `index`: Default file name, default is `index.html`.\r\n- `hidden`: Allow transfer of hidden files. default is `false`.\r\n- `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`.\r\n- `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`.\r\n- `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`.\r\n- `maxage`: Function to set custom headers on response. Browser cache max-age in milliseconds, default is `0`.\r\n- `publicPath`: Public path for route-match. default is `/`.\r\n- `setHeaders`: Function to set custom headers on response. default is `false`. usage: `setHeaders: function(res, path, stats){}`\r\n- `notFoundNext`: If it can't find target file, will continue excuting `next` function.  default is `false`.\r\n\r\n## Contributing\r\n\r\nContributions welcome!\r\n\r\n## License\r\n\r\n[Mit](https://github.com/thinkjs/think-resource/blob/master/LICENSE)\r\n","readmeFilename":"README.md"}