You can see here :

Routing Location :

You can find routing configuration in bundle repository under Resources/config/ directory.

$ ll src/nodefony/bundles/documentation-bundle/Resources/config/

total 24
-rwxr-xr-x  1 cci  staff  1060 10 oct 09:37 config.yml
-rwxr-xr-x  1 cci  staff  2036 10 oct 09:37 routing.js
-rw-r--r--  1 cci  staff   536 10 oct 09:37 services.js
...
	
Autoloader Routing files

File routing.js :

The nodefony Autoloader load configuration file in Resources/config directory which match with 'routing.js'

module.exports = {
	home:{
		pattern:  "/home",
		defaults: {
			controller: "appBundle:default:index"
		},
		requirements: {
			method: ["GET"]
		}
	},
	myroute: {
		pattern: "/myroute/{page}/{elements}",
		defaults: {
			controller: "appBundle:default:myroute",
			page: 13,
			elements: "myDefaultValue"
		},
		requirements: {
			method: ["GET"],
			page: /^\d\d$/
		}
	}
};
				

File routing.yml :

The nodefony Autoloader load configuration file in Resources/config directory which match with 'routing.yml'

documentation:
  pattern:  /documentation
  defaults: {controller: "documentation-bundle:default:index"}
  requirements:
    method: GET

documentation-search:
  pattern:  /documentation/search
  defaults: {controller: "documentation-bundle:default:search"}

documentation-default:
  pattern:  /documentation/{version}
  defaults: {controller: "documentation-bundle:default:index"}

documentation-version:
  pattern:  /documentation/{version}/{bundle}
  defaults: {controller: "documentation-bundle:default:version"}

documentation-section:
  pattern:  /documentation/{version}/{bundle}/{section}
  defaults: {controller: "documentation-bundle:default:version"}

documentation-git-getMostRecentCommit:
  pattern:  /api/git/getMostRecentCommit
  defaults: {controller: "documentation-bundle:git:getMostRecentCommit"}

documentation-git-getStatus:
  pattern:  /api/git/getStatus
  defaults: {controller: "documentation-bundle:git:getStatus"}


documentation-git-getBranch:
  pattern:  /api/git/getCurrentBranch
  defaults: {controller: "documentation-bundle:git:getCurrentBranch"}
					

File annotationController.js :

The nodefony Autoloader Parse Annotations in Controller File'

/**
 *    @Route ("/test/annotate")
 *    @Host ("nodefony.com")
 */
module.exports = class annotationController extends nodefony.controller {

  constructor(container, context) {
    super(container, context);
  }

  /**
   *   @Route ("/requirements", name="test-annotation-requirements", defaults={"id" = 5},requirements={"id" = "\d+"})
   *   @Method ({"GET","WEBSOCKET"})
   */
  annotationAction(id) {
    return this.render("testBundle::index.html.twig", {
      id: id
    });
  }

  /**
   *    @Method ({ "POST", "PUT", "DELETE"})
   *    @Route ("/noname/{id}", name="", defaults={"id" = 5},requirements={"id" = "\d+"})
   */
  annotation2Action(id) {
    return this.render("testBundle::index.html.twig", {
      id: id
    });
  }

  /**
   *    @Method ({"GET", "POST"})
   *    @Route ("/block/{id}",
   *      name="test-annotation-block",
   *      defaults={"id" = 5},
   *      requirements={"id" = "\d+"})
   *
   */
  annotation3Action(id) {
    return this.render("testBundle::index.html.twig", {
      id: id
    });
  }
};
				

Starting Log :

When starting all routes are registred in router service :

Tue Oct 11 2016 13:12:04 DEBUG AUTOLOADER LOAD  : /Users/cci/repository/nodefony/src/nodefony/bundles/documentation-bundle/documentation-bundle.js
Tue Oct 11 2016 13:12:04 DEBUG KERNEL  :  REGISTER BUNDLE : documentation
Tue Oct 11 2016 13:12:04 DEBUG AUTOLOADER LOAD  : /Users/cci/repository/nodefony/src/nodefony/bundles/documentation-bundle/services/webCrawlerService.js
Tue Oct 11 2016 13:12:05 DEBUG SERVICE KERNEL READER  : CONFIG LOAD FILE :/Users/cci/repository/nodefony/src/nodefony/bundles/documentation-bundle/Resources/config/config.yml
Tue Oct 11 2016 13:12:05  DEBUG SERVICE KERNEL READER  : ROUTER LOAD FILE :/Users/cci/repository/nodefony/src/nodefony/bundles/documentation-bundle/Resources/config/routing.yml
Tue Oct 11 2016 13:12:05 DEBUG SERVICE ROUTER  : ADD Route : /documentation   ===> documentation-bundle:default:index
Tue Oct 11 2016 13:12:05 DEBUG SERVICE ROUTER  : ADD Route : /documentation/search   ===> documentation-bundle:default:search
Tue Oct 11 2016 13:12:05 DEBUG SERVICE ROUTER  : ADD Route : /documentation/{version}   ===> documentation-bundle:default:index
Tue Oct 11 2016 13:12:05 DEBUG SERVICE ROUTER  : ADD Route : /documentation/{version}/{bundle}   ===> documentation-bundle:default:version
Tue Oct 11 2016 13:12:05 DEBUG SERVICE ROUTER  : ADD Route : /documentation/{version}/{bundle}/{section}   ===> documentation-bundle:default:version
Tue Oct 11 2016 13:12:05 DEBUG SERVICE ROUTER  : ADD Route : /api/git/getMostRecentCommit   ===> documentation-bundle:git:getMostRecentCommit
Tue Oct 11 2016 13:12:05 DEBUG SERVICE ROUTER  : ADD Route : /api/git/getStatus   ===> documentation-bundle:git:getStatus
Tue Oct 11 2016 13:12:05 DEBUG SERVICE ROUTER  : ADD Route : /api/git/getCurrentBranch   ===> documentation-bundle:git:getCurrentBranch
Tue Oct 11 2016 13:12:05 DEBUG SERVICE KERNEL READER  : SERVICE LOAD FILE :/Users/cci/repository/nodefony/src/nodefony/bundles/documentation-bundle/Resources/config/services.xml
Tue Oct 11 2016 13:12:05 DEBUG SERVICE INJECTION  : START SERVICE webCrawler( container,kernel )
	

Route :

Route Configuration

Location : Resources/config/routing.yml

routeName:
	pattern:	pattern
	defaults:	{controller: "nameBundle:controller:action"}
	prefix: 	test
	requirements:
		method:	GET,DELETE,POST,PUT,WEBSOCKET
	host:		domain.com
	firewalls:
		bypass:     true
			

Location : Resources/config/routing.js

routeName:{
	pattern:	"pattern",
	prefix:		"test",
	defaults:	{
		controller: "nameBundle:controller:action"
	},
	requirements:{
		method:	["GET","DELETE","POST","PUT","WEBSOCKET"],
	},
	host:		"domain.com",
	firewalls:{
		bypass:     true
	}
}
			

Location : controller/controllerController.js

/**
*    @Route ("/test")
*    @Host ("nodefony.com")
*/
module.exports = class controllerController extends nodefony.controller {
	constructor(container, context) {
		super(container, context);
	}
	/**
	*
	*    @Route ("pattern",
	*      name="routeName",
	*      defaults={"id" = 5},
	*      requirements={"id" = "\d+"})
	*		@Method ({"GET","DELETE","POST","PUT","WEBSOCKET"})
	*
	*/
	actionAction(id) {
		return this.render("appBundle::index.html.twig", {
			id: id
		});
	}
}
			
Parameters Description Data Type Example / Default
routeName Route Name (must be unique ) String documentation-git-getBranch
routeName.pattern URL who match Route
Dynamics varaible can be use with {variable}
String /api/git/getCurrentBranch
/documentation/{version}/{bundle}/{section}
routeName.defaults Default config route Object
routeName.defaults.controller Pattern 'nameBundle:controller:action' String "documentation-bundle:git:getCurrentBranch"
routeName.requirement Object
routeName.requirement.method separator : ","
Must be :
  • GET
  • POST
  • PUT
  • DELETE
  • WEBSOCKET
String, Array All
routeName.host Domain who must match String nodefony.com All
routeName.firewalls Config parameters for firewall Object
routeName.firewalls.bypass Bypass firewall for this route Boolean false

How the routes are mapped to controller :

HTTP context :

A route is a map from a URL path to a controller :

documentation-default:
  pattern:  /documentation/{version}
  defaults: {controller: "documentation-bundle:default:index"}
		
Pattern controller format : documentation-bundle:default:index
Bundle Controller Class Method Name Method Arguments
documentation-bundle defaultController indexAction indexAction( version )
You can find Variables Route in arguments of action in controller .
Example : you want to match URL like /documentation or /documentation/1.0 or /documentation/1.0/nodefony

documentation-bundle/Resources/config/routing.yml :

documentation:
  pattern:  /documentation
  defaults: {controller: "documentation-bundle:default:index"}

documentation-default:
  pattern:  /documentation/{version}
  defaults: {controller: "documentation-bundle:default:index"}

documentation-version:
  pattern:  /documentation/{version}/{bundle}
  defaults: {controller: "documentation-bundle:default:version"}
	

documentation-bundle/controller/defaultController.js :

module.exports =  class defaultController extends nodefony.controller {

	constructor  (container, context){
		super(container, context);
	};

	indexAction (version){

		if( ! version ){
			var defaultVersion = this.kernel.settings.version;
		}else{
			var defaultVersion = version ;
		}
		var url = this.generateUrl("documentation-version",{
			bundle:"nodefony",
			version:defaultVersion
		})
		return this.redirect(url);

	};

	versionAction (version, bundle){
		...
	};
};
	

WEBSOCKET context

A route is a map from a URL path to a controller :
demo-bundle/Resources/config/routing.yml :

demo-websoket:
  pattern:  /demo/websoket
  defaults: {controller: "demo-bundle:websocket:index"}
  requirements:
    method: GET,WEBSOCKET
		
Pattern controller format : demo-bundle:websocket:index
Bundle Controller Class Method Name Method Arguments
demo-bundle websocketController indexAction indexAction( message )
You can find websocket message data (client) in arguments of action in controller .

Example : you want to match 2 cases for pattern /demo/websoket

  • URL context websocket : ws(s)://nodefony.com:5151(5152)/demo/websoket
  • URL context http : http(s)://nodefony.com:5151(5152)/demo/websoket
demo-bundle/controller/websocketController.js :

module.exports = class websocketController extends nodefony.controller {

	constructor (container, context){
		super(container, context);
	};

	indexAction (message){

		var context = this.getContext();

		switch( this.getMethod() ){
			case "GET" :
				return this.render('demo-bundle:Default:websocket.html.twig',{name:"websoket"});
			break;
			case "WEBSOCKET" :
				if (message){
					// MESSAGES CLIENT
					this.logger( message.utf8Data , "INFO");
				}else{
					// PREPARE  PUSH MESSAGES SERVER
					// SEND MESSAGES TO CLIENTS
					var i = 0 ;
					var id = setInterval( () => {
						var mess = "I am a  message "+ i +"\n" ;
						context.send(mess);
						this.logger( "SEND TO CLIENT :" + mess , "INFO");
						i++
					}, 1000);

					setTimeout( () => {
						clearInterval(id);
						// close reason , descripton
						context.close(1000, "NODEFONY CONTROLLER CLOSE SOCKET");
						id = null ;
					}, 10000);
					this.context.listen(this, "onClose" , () => {
						if (id){
							clearInterval(id);
						}
					})
				}
			break;
			default :
				throw new Error(" METHOD NOT ALLOWED")
		}
	};
};