ksr-serve

4.0.3 • Public • Published

ksr-serve

线上使用包装好 node静态服务

使用

 
#静态服务 
$ ksr-serve --help
 
  Usage: ksr-serve [options]
 
  Options:
 
    -p, --port [port]      start port (default: 8089)
    -h, --host [host]      start port (default: 127.0.0.1)
    --proxy [proxy]        proxy file , default ".proxy.js" (default: .proxy.js)
    -s, --static [static]  static dir , 逗号分隔 , 默认是当前目录下的dist (default: dist)
    -h, --help             output usage information
 
  1. 支持代理设置 .proxy.js , **此文件需要在线上环境运行, dev 环境也会使用此配置 , 如设置不能再线上运行需要注意判断线上线下环境 ** , 语法请参见 http-proxy , 可根据环境变量区分线上,开发环境
  2. 一般不需配置 增加.ksr.serve.conf.js文件 , **此文件需要在线上环境运行, dev 环境也会使用此配置 , 如设置不能再线上运行需要注意判断线上线下环境 **, 所有在此文件中添加的模块依赖需要添加到 package.jsondependencies选项中 具体参数 如下所示:
module.exports = {
    //webpack-hot-client
    hot:{},
    //webpack-dev-middleware
    dev:{},
    static:[],
    middleware:[],
    proxy: { //[http-proxy-middleware](https://github.com/chimurai/http-proxy-middleware#options)
      "/api": "http://localhost:3000",
      "/api1": {
          target: "http://localhost:3000",
          pathRewrite: {"^/api" : ""}
      },
      "/api2": {
          target: "https://other-server.example.com",
          secure: false
       },
       "/api3": {
           target: "http://localhost:3000",
           bypass: function(req, res, proxyOptions) {
             if (req.headers.accept.indexOf("html") !== -1) {
               console.log("Skipping proxy for browser request.");
               return "/index.html";
             }
           }
        }
    }
}
 

Readme

Keywords

none

Package Sidebar

Install

npm i ksr-serve

Weekly Downloads

14

Version

4.0.3

License

MIT

Unpacked Size

5.6 kB

Total Files

7

Last publish

Collaborators

  • lynn.wang