# think-resource

> Resource for ThinkJS 3.x

Latest version **1.0.3** (published 2017-06-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install think-resource
pnpm add think-resource
yarn add think-resource
bun add think-resource
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2017-06-14 |
| First published | 2017-04-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6.0.0 |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | xiamingxing |
| Maintainers | xiamingxing |
| Keywords | resource, thinkjs, node, static |

## Links

- npm: https://www.npmjs.com/package/think-resource
- Repository: https://github.com/thinkjs/think-resource
- Homepage: https://github.com/thinkjs/think-resource#readme
- Issues: https://github.com/thinkjs/think-resource/issues
- npm.io page: https://npm.io/package/think-resource

## Dependencies (3)

- [debug](https://npm.io/package/debug.md) ^2.6.3
- [koa-send](https://npm.io/package/koa-send.md) 3.3.0
- [think-helper](https://npm.io/package/think-helper.md) latest

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2017-06-14
- 1.0.2 — 2017-06-14
- 1.0.1 — 2017-05-09
- 1.0.0 — 2017-04-18

## README

# think-resource
Resource for ThinkJS 3.x

[![npm](https://img.shields.io/npm/v/think-resource.svg)](https://www.npmjs.com/package/think-resource)
[![Build Status](https://travis-ci.org/thinkjs/think-resource.svg?branch=master)](https://travis-ci.org/thinkjs/think-resource)
[![Coverage Status](https://coveralls.io/repos/github/thinkjs/think-resource/badge.svg?branch=master)](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)

---
_Source: https://npm.io/package/think-resource · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
