0.0.16 • Published 1 year ago

egg-proxy-view v0.0.16

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

egg-proxy-view

NPM version

一般用于代理前端 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

  1. 新增config配置

  2. 更改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.

License

MIT

0.0.16

1 year ago

0.0.15

1 year ago

0.0.14

1 year ago

0.0.13

1 year ago

0.0.12

1 year ago

0.0.11

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago