koajs / koa-hbs

Handlebars templates for Koa.js
MIT License
159 stars 43 forks source link

context.render ends up with 404 #72

Closed 01binary closed 6 years ago

01binary commented 6 years ago

Hello,

This is probably an issue with misunderstanding how koa/koa-hbs work, but it may be useful for others when they have the same problem while learning.

TL;DR: instead of rendering my template, I get a 404 even though my route executes, see https://github.com/01binary/shopper/tree/HandlebarsInitial for a snapshot.

hbs.middleware({
    viewPath: path.resolve(__dirname, '../../dist'),
    extname: '.html'
})
route.get('/', async(context) => {
    console.log('about to render layout')
    await context.render('layout', { mount: render() });
})

When I navigate to my app, I see "about to render layout" logged out, but then it gets a 404:

  <-- GET /
about to render layout
  --> GET / 404 9,964ms -

Why doesn't the hbs middleare render? Does it send a 404 or does koa send a 404? I can't understand what's happening and how to debug it.

Thank you!

01binary commented 6 years ago

OK, inattentive readme reading on my part. I switched to using "next" version of koa-hbs:

  "dependencies": {
    "koa": "^2.3.0",
    "koa-hbs": "next",
  },
shellscape commented 6 years ago

😄