Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yokiyokiyoki/egg-proxy-view
egg proxy devServer html plugin
https://github.com/yokiyokiyoki/egg-proxy-view
devserver egg-plugin eggplugin proxy-html proxy-server
Last synced: 8 days ago
JSON representation
egg proxy devServer html plugin
- Host: GitHub
- URL: https://github.com/yokiyokiyoki/egg-proxy-view
- Owner: yokiyokiyoki
- License: mit
- Created: 2023-03-10T03:22:08.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-03-12T12:43:56.000Z (over 1 year ago)
- Last Synced: 2024-10-29T19:59:49.401Z (19 days ago)
- Topics: devserver, egg-plugin, eggplugin, proxy-html, proxy-server
- Language: JavaScript
- Homepage:
- Size: 35.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# egg-proxy-view
[![NPM version][npm-image]][npm-url]
[npm-image]: https://img.shields.io/npm/v/egg-proxy-view.svg?style=flat-square
[npm-url]: https://npmjs.org/package/egg-proxy-view一般用于代理前端 devServer 的 html,还可以自定义策略代理devServer静态资源以及api
## Install
```bash
$ npm i egg-proxy-view --save
```## Usage
```js
// {app_root}/config/plugin.js
exports.proxyView = {
enable: true,
package: 'egg-proxy-view',
};
```## Configuration
```js
// {app_root}/config/config.local.js
config.proxyView = {
// default默认是false,就不会启动该插件的中间件
open: false,
/**
* devServer配置
*/
devServer:{
host:"127.0.0.1",
port:8899,
},
/**
* 代理相关资源到devServer
*/
targets: [
/^(\/node_modules)/g,
'/assets/(.*)',
'/src/(.*)'
],
}
```see [config/config.default.js](config/config.default.js) for more detail.
## Example
1. 新增config配置
2. 更改ctx.render为ctx.proxyView.render
```ts
@Get('/*')
async home() {
const ctx = this.ctx;
const userAgent = ctx.headers['user-agent'];
const mobileReg = /\s+Mobile/i;
const template = mobileReg.test(userAgent) ? 'mobile.html' : 'index.html';
// 如果open为false,会自动走ctx.render
await ctx.proxyView.render(template, { data: {} });
}
```## Questions & Suggestions
Please open an issue [here](https://github.com/eggjs/egg/issues).
## License
[MIT](LICENSE)