【前端工程】反向代理

Charles配置反向代理

Charles 功能介绍和使用教程前端

一、设置反向代理服务器端口

至关于为目的地设置一个详细地址
image.pngnode

二、反向代理设置映射关系

至关于规划一个从起始点到终点站的地图express

  • 点击Reverse Proxies..

image.png

  • 进入界面,选择Enable选项,并点击add按钮

image.png

image.png

三、SSL Proxy配置

至关于开启代理https服务,在SSL Proxy配置下的host才容许在本地经过https访问请求或接受请求。api

image.png

image.png

Vue项目经过ProxyTable配置反向代理

使用方法

思想:服务器

import * as express from 'express';
import { createProxyMiddleware, Filter, Options, RequestHandler } from 'http-proxy-middleware';
 
const app = express();
 
app.use('/api', createProxyMiddleware({ target: 'http://www.example.org', changeOrigin: true }));
app.listen(3000);
 
// http://localhost:3000/api/foo/bar -> http://www.example.org/api/foo/bar

node 中app

// proxy api requests

Object.keys(proxyTable).forEach(function (context) {

    var  options =  proxyTable\[context\]

    if (typeof  options === 'string') {

    options = { target:  options }

    }

app.use(proxyMiddleware(options.filter ||  context,  options))

})

常见错误

proxyTable 配置无效
proxTabtle 配置错误,好比:pathRewrite中配置 和前端接口请求中url写法不匹配或是接口请求中写死了host,因此不走代理。
其余可能性参考:Vue-cli proxyTable 配置无效问题post

未完待续。url

相关文章
相关标签/搜索