Send to proxy /api
with all params (header/cookie/post) as docs
发送到代理/api,所有的params (header/cookie/post)作为文档
And get
并获得
server.js
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',
},
})
]
}
});
I try another with angular 5, but have the same result(((
我尝试另一个角度为5的,但结果是一样的(
proxy.conf.json
proxy.conf.json
{
"/api": {
"target": "https://security-site.com/",
"secure": false,
"changeOrigin": true,
"logLevel": "info"
}
}
How to solve this problem?
如何解决这个问题?
1 个解决方案
#1
1
I find solution:
我发现解决方案:
Need change header Referal
to https protocol
需要更改头引用到https协议。
For browser-sync
对于browser-sync
server.js
server.js
...
proxy(['/api', '/media'], {
target: 'https://security-site.com',
logLevel: 'debug',
changeOrigin: true,
headers: {
Referer: 'https://security-site.com',
},
})
...
For angular 5 (angular cli): proxy.conf.json
对于角5(角cli): proxy.con .json
{
"/api": {
"target": "https://security-site.com/",
"headers": {
"Referer": "https://security-site.com/"
},
"secure": false,
"changeOrigin": true,
"logLevel": "info"
}
}
#1
1
I find solution:
我发现解决方案:
Need change header Referal
to https protocol
需要更改头引用到https协议。
For browser-sync
对于browser-sync
server.js
server.js
...
proxy(['/api', '/media'], {
target: 'https://security-site.com',
logLevel: 'debug',
changeOrigin: true,
headers: {
Referer: 'https://security-site.com',
},
})
...
For angular 5 (angular cli): proxy.conf.json
对于角5(角cli): proxy.con .json
{
"/api": {
"target": "https://security-site.com/",
"headers": {
"Referer": "https://security-site.com/"
},
"secure": false,
"changeOrigin": true,
"logLevel": "info"
}
}