0

In Express, streaming responses are easy to implement since res is a stream object.

Inside a Feathers custom service method, however, how can I stream something as a response?

4

2 回答 2

1

You might be able to implement a custom response format which pipes res.data if it is a stream, and then resolve your service method with a stream. There is also a discussion about streaming data here.

于 2016-10-21T15:04:41.490 回答
0

You can add a custom service middleware before or after a specific service, and then you can use res.

Example:

const todoService = {
  async get(id) {
    return {
      id,
      description: `You have to do ${id}!`
    };
  }
};

function streamResponse(req, res, next) {
  res.write('Streams are awesome!');
  res.end;
}

app.use('/todos', todoService, streamResponse);
于 2020-03-14T15:27:33.040 回答