question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

With Node.js v7.0.0 out (with V8 5.4), it’s now possible to run Koa v2 using async/await natively, without Babel (albeit behind a --harmony flag).

Would you be able to make a new version of koa-hbs available which will work with Koa v2? (published @next).

(I’ve tried getting the current koa-hbs working with Koa v2 using koa-adapter, but haven’t succeeded).

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
shellscapecommented, Nov 7, 2016

@chrisveness here’s the solution for koa2:

const convert = require('koa-convert');
const co      = require('co');

app.use(convert(hbs.middleware({
    extname:   '.html',
    viewPath:    __dirname + '/',
})));

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

router.get('/', async function(ctx, next) {
  const context = { version: process.version, time: new Date() };
  await ctx.render('hello-world', context);
});
0reactions
shellscapecommented, Jan 17, 2017

koa-hbs@next has been published with full support https://github.com/gilt-labs/koa-hbs/tree/next

Read more comments on GitHub >

github_iconTop Results From Across the Web

Koa - next generation web framework for node.js
A Koa Context encapsulates node's request and response objects into a single object which provides many helpful methods for writing web applications and...
Read more >
koajs/koa: Expressive middleware for node.js using ... - GitHub
Expressive HTTP middleware framework for node.js to make web applications and APIs more enjoyable to write. Koa's middleware stack flows in a stack-like ......
Read more >
koa-socket-2 - npm
Koa-socket-2 is only compatible with Koa v2 style of middleware (where context is passed as a parameter). Koa-socket-2 requires Node v7.0.0 or ...
Read more >
Mastering Koa Middleware - Medium
Learn how Koa's middleware system works and how you can use it to write any ... Koa v2 recently dropped as Node made...
Read more >
koa v2.13.4 Bundlephobia
Size of koa v2.13.4 is 202.2 kB (minified), and 40.5 kB when compressed using GZIP. Bundlephobia helps you find the performance impact of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found