We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
确保你的 nodejs 版本 >= 8.0.0, 解决跨域问题,支持本地开发热更新
yarn add @gauseen/web-proxy -D # 推荐 # or npm i @gauseen/web-proxy -D
// 首先,在项目根目录创建 server.js 文件
// 例子: // server.js const path = require('path') const server = require('@gauseen/web-proxy') const options = { 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 run success ...') }, } server(options)
watch
Boolean
false
watchStatic
String
serverStatic
proxyTable
doman
Object
port
Number
8008
notify
ignores
Array
[css, html, js]
callback
Function
node server.js # 或 # 自己配置 npm scripts 运行 # 更改 server.js 文件后要重启服务,更改才生效
localhost: <port>/
proxyTable 是个对象, 键 为: 请求 URL 的统一标识字段,如请求接口:http://doman/api/back/login,那么 api 就是它的标识字段 值 为: { target: 要代理的(域名或IP) doman, # (必填) pathRewrite: { '^/oldFlag': '/newFlag', } # (非必填) } pathRewrite 字段作用是防止后端接口比较混乱,没有统一的标识符, 这时前端在本地开发时,可以自己添加一个统一标识符,并使用 pathRewrite 的功能,再让这个字段设置为空字符,这样就可以请求到服务端本来的 URL
项目地址
欢迎 star ⭐ ⭐ ⭐ ⭐ ⭐
The text was updated successfully, but these errors were encountered:
gauseen
No branches or pull requests
特别针对老型项目设计,没有使用构建工具( webpack、gulp、grunt etc.)
安装(install)
使用(usage)
// 首先,在项目根目录创建 server.js 文件
options 参数说明:
watch
Boolean
false
watchStatic
String
serverStatic
String
proxyTable
doman
Object
port
Number
8008
notify
Boolean
false
ignores
watch
文件格式Array
[css, html, js]
callback
Function
启动服务
浏览器运行
localhost: <port>/
注:
项目地址
欢迎 star ⭐ ⭐ ⭐ ⭐ ⭐
The text was updated successfully, but these errors were encountered: