rendertron icon indicating copy to clipboard operation
rendertron copied to clipboard

Add Koa middleware

Open glen-84 opened this issue 4 years ago • 4 comments

It would be great if Rendertron included Koa middleware.

I understand that it's not practical to include middleware for every available framework, but Rendertron just so happens to depend on multiple Koa packages anyway, so it seems like it would be a good fit.

glen-84 avatar Apr 13 '21 08:04 glen-84

I think now is a good time to retire the express middleware and move to koa. Would you be interested in doing that?

AVGP avatar Apr 13 '21 18:04 AVGP

@AVGP,

I'm in the process of writing Koa middleware, so I might be able to contribute that here.

I had started using Axios instead of the deprecated request, because I thought that node-fetch only supported timeouts using the awkward AbortController, but I see now (in your PR and in the docs), that there is in fact a timeout option, even though it does state "Signal is recommended instead". Do you still prefer node-fetch? (see also https://github.com/node-fetch/node-fetch/issues/523#issuecomment-438158003)

I'm not sure about replacing the Express middleware though, as there are many users using that framework (as dead as it appears to be). That's obviously your call though.

glen-84 avatar Apr 13 '21 19:04 glen-84

@AVGP Do you have a moment to respond to the questions above? 🙂

glen-84 avatar Apr 15 '21 11:04 glen-84

Koa middleware for Rendertron (using Axios).

Usage:

app.use(
    makeMiddleware({
        proxyUrl: "http://my-rendertron-instance/render"
    })
);

glen-84 avatar Apr 20 '21 09:04 glen-84

In general, as we're deprecating the project, you should look into alternative approaches to rendering on the web.

AVGP avatar Oct 06 '22 08:10 AVGP