Risotto is a VC framework based on koajs. it makes heavy use of es6 harmony features and thus requires node´s **--harmony** flag
Last updated 3 years ago by heythere .
MIT · Repository · Bugs · Original npm · Tarball
$ cnpm install risotto 
SYNC missed versions from official npm registry.

#Risotto Risotto is a VC framework based on koajs.

##Install Risotto requires redis to run

$ npm install risotto

#Scaffolding Risotto needs a special project structure to run:



Require Risotto where ever you want and pass the those folders to the initialize method like this: it makes heavy use of es6 harmony features and thus requires node´s --harmony flag


After calling initialize Risotto will boot up and look up all controllers in /app/controllers. It will bind all routes configured in the /config/routes.yml file for you. Be Aware Risotto will register a global variable named "Risotto".

##Controllers Controllers take the main part in handling incoming requests and processing them.

A controller consists of a group of methods which handle one type of request defined in the route. Example:

module.exports = Risotto.Controller.extend({
	index : function*(params){
		yield this.render("dashboard/index", {user : user });

The params object passed to each method contains every parameter that might be passed to the server. In the methods you have access to the following methods:

this.render(pathToView, options = {})

Generator Function which renders and returns a html template at path. Everything into the options object will be available as variable in the template.

this.body =

setter/getter for the response body

###this.status = setter/getter for the response status code

###this.redirect(path) Redirects the Request to path

###this.error(code [, message]) Returns an http error with the given code and optional with the message.

###this.attachment access to the koa attachment method

###this.json access to the koa method json

###this.type access to the koa attribute type

###this.session access to the koa attribute session

###this.request access to the koa request object

###this.response access to the koa response object

##Routes The routes file in the config directory contains all the individual routes to the controllers. It has the following syntax:

 GET /:username/: Profile.show

###namespacing Routes can be namespaced in the following way:

  GET :id-(.+): Project.show


module.exports = Risotto.Application.extend({
	// process title
	title: "My Risotto App",
	onAuthorizationError : function*(koaContext, next){
		//do something onAuthorizationError

	onNotFoundError : function*(koaContext, next){
		// do something onNotFoundError

	onError : function*(koaContext, next){
		// do something onError

##Modules …

##Filters Filters are a way to reuse common controller functionality. We differentiate between beforeFilter which run before the controller and the afterFilter which run after the actual controller. ###Using Filters

	// calls the `user` and the `authorize` filter before
	beforeFilter: ['user', 'authorize']

	beforeFilter: {
		 * calls `user` filter before 
		 * all controller methods
		user: '*', 

		 * calls `authorize` filter only 
		 * before protectedMethod
		authorize: 'protectedMethod',

		 * calls `foo` filter only 
		 * before protectedMethod and show
		foo: ['show', 'protectedMethod']

###Defining Filters Create a new file in app/filters and call Risotto.before to register a beforeFilter and Risotto.after to register a afterFilter.

Risotto.before('user', function*(){
	if( !this.session || !this.session.user_id ){
	//`this` referes to the controller context
	this.user = yield User.findOne({ id: this.session.user_id });
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 3
Dependencies (28)
Dev Dependencies (3)
Dependents (1)

Copyright 2014 - 2018 © taobao.org |