Fork me on GitHub

Nodefony Documentation

default



Getting Started with Nodefony

More details

NODEFONY INSTALLATION : See more ( Nodefony installation documentation )

Install Nodefony Globally

Install with NPM :

$ npm -g install nodefony

Install with yarn :

$ yarn global add nodefony

See Global install How to Prevent Permissions Errors

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
  domainCheck                   : true
  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                       : "file:src/bundles/hello-bundle"

  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 "demo-bundle"

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: "documentation-bundle: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: "documentation-bundle: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('documentation-bundle:demo:index.html.twig', {
  name:name,
  });
  }
};
  
<h1> {{name}} </h1>
  

nodefony

Rendering Websocket :

Rendering Websocket

URL : ws://localhost:5151/websoket

websoket:
  pattern:  /websoket
  defaults: {"controller": "demo-bundle: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('demo-bundle: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": "demo-bundle: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