koajs / koa-hbs

Handlebars templates for Koa.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cache bug

einsqing opened this issue · comments

koa.use(convert(hbs.middleware({
    extname: '.html',
    viewPath: ['./www/admin', './www/home'],
    layoutsPath: './www',
    partialsPath: ['./www/admin', './www/home'],
    disableCache: true
})));

koa.use(async(ctx, next) => {
    const render = ctx.render;
    ctx.render = async function _convertedRender() {
        return co.call(ctx, render.apply(ctx, arguments))
    }

    await next();
});

###render###

 if(ctx.query.type){
       ctx.state = {
             layout: 'admin/override'
       };
}

await ctx.render('index_index');

If I open the cache, view rendering not to come out, when I closed the cache, the view can render.

I'm not sure I understand. could you rephrase?

497d7471-fbc4-48db-9527-1f7cfba7b8af

Actually return data, but this. The body has no output to the browser

so that looks like a koa2 issue. support for that is hacked together with koa-convert and some middleware trickery, but it's not built in. if you find a solution, I'd be happy to add it to the readme. but this might have to wait until Koa2 support is official.

After using async/await rewrite koa-hbs, I found this not koa or koa-convert bug, this is my own writing async function called dynamic, not await.Contribute a koa-hbs for koa2 https://github.com/einsqing/koa2-hbs