https://github.com/eggjs/static
static server plugin for egg
https://github.com/eggjs/static
egg egg-plugin egg-static
Last synced: 12 months ago
JSON representation
static server plugin for egg
- Host: GitHub
- URL: https://github.com/eggjs/static
- Owner: eggjs
- License: mit
- Created: 2016-07-15T07:15:28.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2025-01-12T15:25:29.000Z (about 1 year ago)
- Last Synced: 2025-01-12T15:41:49.545Z (about 1 year ago)
- Topics: egg, egg-plugin, egg-static
- Language: TypeScript
- Homepage:
- Size: 45.9 KB
- Stars: 91
- Watchers: 10
- Forks: 16
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-egg - egg-static - 静态服务器插件。   (仓库 / [内置插件](https://eggjs.org/zh-cn/basics/plugin.html#%E6%8F%92%E4%BB%B6%E5%88%97%E8%A1%A8))
README
# @eggjs/static
[![NPM version][npm-image]][npm-url]
[](https://github.com/eggjs/static/actions/workflows/nodejs.yml)
[![Test coverage][codecov-image]][codecov-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]
[](https://nodejs.org/en/download/)
[](https://makeapullrequest.com)
[npm-image]: https://img.shields.io/npm/v/@eggjs/static.svg?style=flat-square
[npm-url]: https://npmjs.org/package/@eggjs/static
[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/static.svg?style=flat-square
[codecov-url]: https://codecov.io/github/eggjs/static?branch=master
[snyk-image]: https://snyk.io/test/npm/@eggjs/static/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/@eggjs/static
[download-image]: https://img.shields.io/npm/dm/@eggjs/static.svg?style=flat-square
[download-url]: https://npmjs.org/package/@eggjs/static
Static server plugin for egg, base on [@eggjs/koa-static-cache](https://github.com/eggjs/koa-static-cache).
## Install
`@eggjs/static` is a plugin that has been built-in for egg. It is enabled by default.
## Configuration
`@eggjs/static` support all configurations in [@eggjs/koa-static-cache](https://github.com/eggjs/koa-static-cache).
And with default configurations below:
- prefix: `'/public/'`
- dir: `path.join(appInfo.baseDir, 'app/public')`
- dynamic: `true`
- preload: `false`
- maxAge: `31536000` in prod env, `0` in other envs
- buffer: `true` in prod env, `false` in other envs
`@eggjs/static` provides one more option:
- maxFiles: the maximum value of cache items, only effective when dynamic is true, default is `1000`.
**All static files in `$baseDir/app/public` can be visited with prefix `/public`, and all the files are lazy loaded.**
- In non-production environment, assets won't be cached, your modification can take effect immediately.
- In production environment, `@eggjs/static` will cache the assets after visited, you need to restart the process to update the assets.
- Dir default is `$baseDir/app/public` but you can also define **multiple directory** by use `dir: [dir1, dir2, ...]` or `dir: [dir1, { prefix: '/static2', dir: dir2 }]`, static server will use all these directories.
```ts
// {app_root}/config/config.default.ts
export default {
static: {
// maxAge: 31536000,
},
};
```
## Questions & Suggestions
Please open an issue [here](https://github.com/eggjs/egg/issues).
## License
[MIT](LICENSE)
## Contributors
[](https://github.com/eggjs/static/graphs/contributors)
Made with [contributors-img](https://contrib.rocks).