Send response after data is load

  javascript, koa

I was wondering how I can send a response at KOA server after I sent async request and it takes long time (2-3 minutes) for loading the data.

router.get('/getAllProducts', async (ctx, next) => {
      axios.get('/data').then((res) => {
        ctx.body = res;
  });
});

If I send a request to /getAllProducts and I am getting 404 error.
But if I change my code to:

   router.get('/getAllProducts', async (ctx, next) => {
          ctx.response.status = 200;
          axios.get('/data').then((res) => {
            ctx.body = res;
      });
    });

The error is gone but how I can retrieve the res data from client

Source: Ask Javascript Questions

LEAVE A COMMENT