我使用http-proxy-middleware
创建了一个浏览器代理,如下所示:
var proxyMiddleware = require('http-proxy-middleware');
var proxy = proxyMiddleware('/api', {
target: 'https://xxx.xxx.xxx.xxx/api',
changeOrigin: true // for vhosted sites, changes host header to match to target's host
});
当服务器启动时,它会创建代理:
[HPM] Proxy created: /api -> https://xxx.xxx.xxx.xxx/api
但是,由于开发API使用自签名证书,因此在调用API时会抛出以下错误。
[HPM] Proxy error: DEPTH_ZERO_SELF_SIGNED_CERT. undefined -> "xxx.xxx.xxx.xxx/api"
有没有办法禁用它?
答案 0 :(得分:1)
是的,您应该传递secure:false flag
var proxy = proxyMiddleware('/api', {
target: 'https://xxx.xxx.xxx.xxx/api',
changeOrigin: true,
secure: false
});