创建本地服务,和服务代理,支持热更新创建http代理支持热更新TODO是专门为老项目设计的,不使用构建工具(webpack,gulp,grunt等)确保你的nodejs版本>=8.0.0,以解决跨域问题,支持本地开发热更新安装(install)yarnadd@gauseen/web-proxy-D#Recommend#ornpmi@gauseen/web-proxy-Dusage(用法)//首先在项目根目录。js文件//示例://server.jsconstpath=require('path')constserver=require('@gauseen/web-proxy')constoptions={watch:false,watchStatic:path.join(__dirname,'./demo/'),serverStatic:path.join(__dirname,'./'),port:8008,proxyTable:{'/api':{target:'http://doman.com/',}/*'/apiFlag':{target:'http://doman.com/',pathRewrite:{//^/old-path':'/new-path//下面的配置是重写以/开头的请求apiFlag写成/newFlag,或''(空)'^/apiFlag':'/newFlag',}}*/},notify:true,//ignores:['js'],callback:function(){console.log('服务器运行成功...')},}server(options)options参数说明:参数说明类型默认必填optionaloptionwatch是否开启热更新Booleanfalseyes-watchStatic热更新目录Stringyes-server静态静态服务目录Stringyes-proxyTabledoman要代理的对象yes-port端口号8008no-notify是否在浏览器端显示通知BooleanfalseNo-ignores忽略watch文件格式Array-No[css,html,js]callback服务启动成功callbackFunction-No-startservicenodeserver.js#or#Configurenpmscripts自行运行#更改server.js文件需要重启才能使更改生效。浏览器运行localhost:
