Check that response hasn't been sent already
NickBolles opened this issue · 2 comments
NickBolles commented
I know it's a little bit out of the KOA architecture. But say we want to handle the response ourselves, koa-compress will always log an "ERR_HTTP_HEADERS_SENT"
Sure I can delete the body after it's sent or do some other weird hack, but it seems like koa-compress should check ctx.headerSent or ctx.respond`
A use case for this is with a next.js custom server, which I'm making a middleware for next.js to use in Strapi. Here's the middleware code
const router = new Router();
const handle = nextApp.getRequestHandler();
router.get('*', async (ctx, next) => {
await next();
if (ctx.response.status === 404) {
ctx.respond = false;
await handle(ctx.req, ctx.res);
}
});
strapi.app.use(router.routes());
jonathanong commented
@NickBolles usually this is from developer error where a middleware is sending headers when it shouldn't. however, I am not opposed to checking ctx.headerSent
jonathanong commented
does #70 solve it?