egg-proxy-view
v0.0.16
Published
[![NPM version][npm-image]][npm-url]
Downloads
0
Readme
egg-proxy-view
一般用于代理前端 devServer 的 html,还可以自定义策略代理devServer静态资源以及api
Install
$ npm i egg-proxy-view --save
Usage
// {app_root}/config/plugin.js
exports.proxyView = {
enable: true,
package: 'egg-proxy-view',
};
Configuration
// {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 for more detail.
Example
新增config配置
更改ctx.render为ctx.proxyView.render
@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.