Because now the render.renderToString function return nothing, but its a async function, i need return response in its callback, it will lead to bug in koa. I have to wrap it to a function return promise to let it to work. Something like this:
function render(renderer) {
let resolve;
const promise = new Promise(r => resolve = r);
renderer.renderToString(context, (err, html) => {
resolve(html);
});
return promise;
}
server.get('*', async ctx => {
const res = await render(renderer);
ctx.status = 200;
ctx.body = res;
})
Maybe the render.renderToString return a promise will be better ?
What does the proposed API look like?koa2:
server.get('*', async ctx => {
const res = await renderer.renderToString(context);
ctx.status = 200;
ctx.body = res;
})
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4