context.render ends up with 404
01binary opened this issue · comments
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.
- I setup koa middleware to look for templates in projectdir/dist with .html extension. I have layout.html file there (after executing
yarn build
):
hbs.middleware({
viewPath: path.resolve(__dirname, '../../dist'),
extname: '.html'
})
- The template looks like this (it was generated by Html Webpack 2 plugin, react dom render goes in "mount"):
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>App</title>
</head>
<body>
<div id="app">
{{mount}}
</div>
<script type="text/javascript" src="scripts/vendor.js?83f7fa2dc8d8f8322d36"></script><script type="text/javascript" src="scripts/app.js?83f7fa2dc8d8f8322d36"></script></body>
</html>
- I "use" the middleware as directed...
- In my "/" route, I have:
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!
OK, inattentive readme
reading on my part. I switched to using "next" version of koa-hbs:
"dependencies": {
"koa": "^2.3.0",
"koa-hbs": "next",
},
😄