发送给代理/api
,所有参数(标题/ Cookie /帖子)为docs
得到
server.js
'use strict';
const fs = require('fs'),
proxy = require('http-proxy-middleware'),
browserSync = require('browser-sync').create();
function returnIndexPageFn(req, res, next) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(fs.readFileSync('./public/app.html'));
res.end();
next();
}
browserSync.init({
port: 88,
server: {
baseDir: 'public/',
index: 'app.html',
middleware: [
{route: '/home', handle: returnIndexPageFn},
proxy(['/api', '/media'], {
target: 'https://security-site.com',
logLevel: 'debug',
changeOrigin: true,
headers: {
Referer: 'https://security-site.com',
},
})
]
}
});
我用角度5尝试另一个,但结果相同((
proxy.conf.json
{
"/api": {
"target": "https://security-site.com/",
"secure": false,
"changeOrigin": true,
"logLevel": "info"
}
}
如何解决这个问题?
答案 0 :(得分:1)
我找到解决方案:
需要将标题Referal
更改为 https 协议
<强> server.js 强>
...
proxy(['/api', '/media'], {
target: 'https://security-site.com',
logLevel: 'debug',
changeOrigin: true,
headers: {
Referer: 'https://security-site.com',
},
})
...
对于角度5(角度cli): 的 proxy.conf.json 强>
{
"/api": {
"target": "https://security-site.com/",
"headers": {
"Referer": "https://security-site.com/"
},
"secure": false,
"changeOrigin": true,
"logLevel": "info"
}
}