Skip to content

Instantly share code, notes, and snippets.

@victor36max
Created April 7, 2018 12:49
Show Gist options
  • Save victor36max/31fea678f8f3cd73324923905ba77818 to your computer and use it in GitHub Desktop.
Save victor36max/31fea678f8f3cd73324923905ba77818 to your computer and use it in GitHub Desktop.
const keystone = require('keystone');

// Setup Route Bindings
exports = module.exports = nextApp => keystoneApp => {

	// Next request handler
	const handle = nextApp.getRequestHandler();

	keystoneApp.get('/api/posts', (req, res, next) => {
		const Post = keystone.list('Post');
		Post.model
			.find()
			.where('state', 'published')
			.sort('-publishedDate')
			.exec(function (err, results) {
				if (err) throw err;
				res.json(results);
			});
	});

	keystoneApp.get('*', (req, res) => {
		return handle(req, res);
	});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment