Fork me on GitHub

Nodefony Documentation

default



Getting Started with Nodefony

More details

NODEFONY INSTALLATION : See more ( Nodefony installation documentation )

Get sources from gitHub


$ git clone https://github.com/nodefony/nodefony.git

$ cd nodefony

$ make build

Configurations : See more ( Nodefony Configurations documentation )

By defaut NODEFONY bind all servers on loopback ( localhost : 127.0.0.1 )

  • domain : localhost
  • http : 5151
  • https: 5152

If you want change listen port http(s) by defaut or domain ( Configurations framework )
Change config.yml Location : ./config/config.yml

system:
  domain                        : localhost             # nodefony can listen only one domain ( no vhost )  /    [::1] for IPV6 only
  domainAlias:                                          # domainAlias string only <>   example ".*\\.nodefony\\.com  ^nodefony\\.eu$ ^.*\\.nodefony\\.eu$"
    - "^127.0.0.1$"
  httpPort                      : 5151
  httpsPort                     : 5152
  statics                       : true
  security                      : true
  realtime                      : true
  monitoring                    : true
  documentation                 : true
  unitTest                      : true
  locale                        : "en_en"

  servers:
    http                        : true
    https	                : true
    ws			        : true
    wss			        : true
    certificats:
      key                       : "config/certificates/server/privkey.pem"
      cert                      : "config/certificates/server/fullchain.pem"
      ca                        : "config/certificates/ca/nodefony-root-ca.crt.pem"
      options:
        rejectUnauthorized      : false

  bundles:
    hello                       : "src/bundles/demoBundle"

  log:
    active                      : true

#
#       ASSETS CDN
#
#       You set cdn with string
#       CDN :   cdn.nodefony.com
#       or
#       CDN:
#          global: cdn.nodefony.com
#       or
#       CDN:
#         stylesheet:
#           - cdn.nodefony.com
#         javascript:
#           - cdn.nodefony.com
#         image:
#           - cdn.nodefony.com
#           - cdn.nodefony.fr
#         font:
#           - cdn.nodefony.com
#
CDN                             : ~
  

Running NODEFONY : See more ( RUN Nodefony documentation )


# Run Appliation in DEV mode

$ ./nodefony dev

  

ACCEES NODEFONY APPLICATION :

Access to App with URL : http://localhost:5151
By default the nodefony clone come with a demonstration bundle named "demoBundle"

SIMPLE EXAMPLES NODEFONY FRAMEWORK :

Rendering html :

Simple Render html

URL : http://localhost:5151/doc/demo/html/nodefony

module.exports = {
  "documentation-demo": {
    pattern: "/doc/demo/html/{name}",
    defaults: {
      controller: "documentationBundle:demo:html",
      name:	"nodefony"
    }
  }
};
  

/*
 *	Class demoController
 *
 */
module.exports = class demoController extends nodefony.controller {
  /*
   *	CONSTRUCTOR
   */
  constructor (container, context){
    super(container, context);
  }
  /*
 	*	Action html
 	*
 	*/
  htmlAction (name){
    return this.renderResponse('<h1>'+name+'</h1>');
  }
};
  

nodefony

Rendering Templates :

Rendering Twig Templates

URL : http://localhost:5151/doc/demo/render/nodefony

documentation-demo-render:
  pattern:  /doc/demo/render/{name}
  defaults: {controller: "documentationBundle:demo:render", "name":"nodefony"}
  

/*
 *	Class demoController
 *
 */
module.exports = class demoController extends nodefony.controller {
  /*
   *	CONSTRUCTOR
   */
  constructor (container, context){
    super(container, context);
  }
  /*
 	*	Action render
 	*
 	*/
  renderAction (name){
    return this.render('documentationBundle:demo:index.html.twig', {
  name:name,
  });
  }
};
  
<h1> {{name}} </h1>
  

nodefony

Rendering Websocket :

Rendering Websocket

URL : ws://localhost:5151/websoket

websoket:
  pattern:  /websoket
  defaults: {"controller": "demoBundle:demo:websoket"}
  requirements:
    method:
      - GET
      - WEBSOCKET
  

/*
*	Class demoController
*
*/
module.exports = class demoController extends nodefony.controller {
  /*
  *	CONSTRUCTOR
  */
  constructor (container, context){
    super(container, context);
  }
  /*
  *	Action websoket
  *
  */
  websoketAction (message){
    switch( this.getMethod() ){
      case "GET" :
        return this.render('demoBundle:Default:websocket.html.twig',{name:"websoket"});
      case "WEBSOCKET" :
        if (message){
          // LOG  MESSAGE CLIENT IN TERMINAL
          this.logger( message.utf8Data , "INFO");
        }else{
          // PREPARE  PUSH MESSAGES SERVER
          // SEND MESSAGES TO CLIENTS
          let i = 0 ;
          let id = setInterval(() => {
            let mess = "I am a  message "+ i +"\n" ;
             // You can use context to send data
            this.context.send(mess);
            //  or call controller method ( renderResponse , render , renderJson )
            this.renderResponse(mess);
            // LOG  MESSAGE SENDING IN TERMINAL
            this.logger( "SEND TO CLIENT :" + mess , "INFO");
            i++
          }, 1000);

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


/* YOU CAN SHOW LOG IN TERMINAL */

Thu Oct 06 2016 15:49:09 INFO REQUEST WEBSOCKET SECURE  :  Connection Websocket Connection from : 192.168.100.71 PID :86607 ORIGIN : https://nodefony.com:5152
Thu Oct 06 2016 15:49:09 INFO CONTROLER demo   :  HELLO SERVER I AM A CLIENT : Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2879.0 Safari/537.36

Thu Oct 06 2016 15:49:10 INFO CONTROLER demo   : SEND TO CLIENT :I am a  message 0
Thu Oct 06 2016 15:49:11 INFO CONTROLER demo   : SEND TO CLIENT :I am a  message 1
Thu Oct 06 2016 15:49:12 INFO CONTROLER demo   : SEND TO CLIENT :I am a  message 2
Thu Oct 06 2016 15:49:13 INFO CONTROLER demo   : SEND TO CLIENT :I am a  message 3
Thu Oct 06 2016 15:49:14 INFO CONTROLER demo   : SEND TO CLIENT :I am a  message 4
Thu Oct 06 2016 15:49:15 INFO CONTROLER demo   : SEND TO CLIENT :I am a  message 5
Thu Oct 06 2016 15:49:16 INFO CONTROLER demo   : SEND TO CLIENT :I am a  message 6
Thu Oct 06 2016 15:49:17 INFO CONTROLER demo   : SEND TO CLIENT :I am a  message 7
Thu Oct 06 2016 15:49:18 INFO CONTROLER demo   : SEND TO CLIENT :I am a  message 8

Thu Oct 06 2016 15:49:19 INFO REQUEST WEBSOCKET SECURE  : Thu Oct 06 2016 15:49:19 GMT+0200 (CEST) Connection Websocket CLOSE : 192.168.100.71 PID :86607 ORIGIN : https://nodefony.com:5152 1000 NODEFONY CONTROLLER CLOSE SOCKET
  

Rendering JSON :

Rendering JSON

URL : http://localhost:5151/json

json:
  pattern:  /json
  defaults: {"controller": "demoBundle:demo:json"}
  
/*
 *	Class demoController
 *
 */
module.exports = class demoController extends nodefony.controller {
  /*
   *	CONSTRUCTOR
   */
  constructor (container, context){
    super(container, context);
  }
  /*
   *	Action json
   *
   */
  jsonAction (){
    return this.renderJson({
      foo:"bar",
      bar:"foo"
    });
  }
};
  

Local Recent Commits
GitHub Issue Queue Activity