Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

context.render ends up with 404 #72

Closed
01binary opened this issue Aug 31, 2017 · 2 comments
Closed

context.render ends up with 404 #72

01binary opened this issue Aug 31, 2017 · 2 comments

Comments

@01binary
Copy link

01binary commented Aug 31, 2017

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!

@01binary
Copy link
Author

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
Copy link
Contributor

😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants