Giter Club home page Giter Club logo

Comments (10)

lee-my avatar lee-my commented on May 31, 2024 1

router.all('*', async ctx => {
const requestStream = apiProxy.proxyRequest(ctx);
const pt = requestStream.pipe(PassThrough());
await new Promise(resolve => {
requestStream.on('response', response => {
ctx.set('content-type', response.headers['content-type']);
resolve();
});
});
ctx.body = pt;
});

这样写好了

from koa-web-kit.

lee-my avatar lee-my commented on May 31, 2024

image
像这样 返回的不是一个完整的json

from koa-web-kit.

JasonBoy avatar JasonBoy commented on May 31, 2024

直接调接口会没么

from koa-web-kit.

lee-my avatar lee-my commented on May 31, 2024

直接调接口是好的

from koa-web-kit.

JasonBoy avatar JasonBoy commented on May 31, 2024

可能是stream被某种网络原因关了吧,你在proxy.js里再pipe给PassThrough试一下:

const {PassThrough} = require('stream');
//....
router.all('*', ctx => {
    ctx.body = apiProxy.proxyRequest(ctx).pipe(PassThrough());
  });

from koa-web-kit.

lee-my avatar lee-my commented on May 31, 2024

厉害啊!! 好了
这是什么原因啊?

from koa-web-kit.

JasonBoy avatar JasonBoy commented on May 31, 2024

koajs/koa#612

from koa-web-kit.

lee-my avatar lee-my commented on May 31, 2024

抱歉 又出现一个问题
返回的接口数据,在network中中文显示乱码了 页面上显示正常

WX20190327-161551@2x2222222

from koa-web-kit.

lee-my avatar lee-my commented on May 31, 2024

就谷歌会出现这样 火狐是好的

from koa-web-kit.

JasonBoy avatar JasonBoy commented on May 31, 2024

🤦‍♂️ 应该是PassThrough不会把header 回给浏览器,试试先set头,然后再pipe:

    const requestStream = proxy.proxyRequest(ctx);
    const pt = requestStream.pipe(PassThrough());
    await new Promise(resolve => {
      requestStream.on('response', response => {
        ctx.status = response.statusCode;
        ctx.set(response.headers);
        resolve();
      });
    });
    ctx.body = pt;

from koa-web-kit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.