You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
proxy.when([condition,] callback)
proxy.index('/index.html')
proxy.mockfile(mockfile, needLocal)
proxy.open('/index.html')
proxy.static(root, opts)
版本更新(使用lazy-doc打包自doc/history.md)
proxy.when('/api', function(ctx) {
ctx.request.host = 'www.test.com';
ctx.request.protocol = 'http';
// 配置代理请求结束后修改body
proxy.when({'.html', phase: 'response'}, function(ctx) {
ctx.response.body += '<div>test</div>';
// 请求开始时转发本地请求到网络
proxy.on('start', function (ctx) {
console.log('start: ', ctx.request.url, ctx.isLocal());
ctx.request.host = 'www.koa2.com';
// 请求结束时输出状态
proxy.on('end', function (ctx) {
console.log('end: ' + ctx.response.status);
console.log('end: ' + ctx.response.get('content-type'));
// console.log('end: ' + ctx.response.body);
// 监听端口
proxy.listen(3010);