Fork me on GitHub

nodefony 5.0.5



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 all network interfaces ( 0.0.0.0 )

  • domain : localhost or ip ( LAN )
  • http : 5151
  • https: 5152

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


  /**
   *  NODEFONY FRAMEWORK
   *
   *       KERNEL CONFIG
   *
   *   Domain listen : Nodefony can listen only one domain ( no vhost )
   *     Example :
   *      domain :  0.0.0.0      // for all interfaces
   *      domain :  [::1]        // for IPV6 only
   *      domain :  192.168.1.1  // IPV4
   *      domain :  mydomain.com // DNS
   *
   *   Domain Alias : string only "<>" use domainCheck : true
   *     Example :
   *      domainAlias:[
   *        "^127.0.0.1$",
   *        "^localhost$",
   *        ".*\\.nodefony\\.com",
   *        "^nodefony\\.eu$",
   *        "^.*\\.nodefony\\.eu$"
   *      ]
   */
  const path = require("path");

  module.exports = {
    system: {
      domain: "0.0.0.0",
      domainAlias: [
        "^127.0.0.1$",
        "^localhost$"
      ],
      httpPort: 5151,
      httpsPort: 5152,
      domainCheck: false,
      locale: "en_en",
      /**
       * BUNDLES CORE
       */
      security: true,
      realtime: true,
      monitoring: true,
      mail: true,
      documentation: true,
      unitTest: true,
      redis: false,
      mongo: false,
      elastic: false,
      /**
       * SERVERS
       */
      servers: {
        statics: true,
        protocol: "2.0", //  2.0 || 1.1
        http: true,
        https: true,
        ws: true,
        wss: true,
        certificats: {
          key: path.resolve("config", "certificates", "server", "privkey.pem"),
          cert: path.resolve("config", "certificates", "server", "fullchain.pem"),
          ca: path.resolve("config", "certificates", "ca", "nodefony-root-ca.crt.pem"),
          options: {
            rejectUnauthorized: true
          }
        }
      },
      /**
       * DEV SERVER
       */
      devServer: {
        inline: true,
        hot: false,
        hotOnly: false,
        overlay: true,
        logLevel: "info", // none, error, warning or info
        progress: false,
        protocol: "https",
        websocket: true
      },
      /**
       *  BUNDLES LOCAL REGISTRATION
       *    Examples :
       *       bundles:{
       *         "hello-bundle" : "file:src/bundles/hello-bundle",
       *         "hello-bundle" : path.resolve(__dirname, "..", "src", "bundles", "hello-bundle"),
       *         "hello-bundle" : path.resolve("src", "bundles", "hello-bundle")
       *       }
       */
      bundles: {
        "hello-bundle": "file:src/bundles/hello-bundle",
      },
      /**
       * SYSLOG NODEFONY
       */
      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: null,

    /**
     *  ENGINE TEMPLATE
     *
     *       TWIG
     *       https://github.com/justjohn/twig.js
     *
     */
    templating: "twig",

    /**
     * ENGINE ORM
     *       sequelize || mongoose
     *   orm : mongoose
     */
    orm: "sequelize",

    /**
     * NODE.JS PACKAGE MANAGER
     *
     *       npm
     *       yarn
     */
    packageManager: "npm"

  };

  

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

SIMPLE EXAMPLES NODEFONY FRAMEWORK :

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"
    }
  }
};
            

module.exports = class demoController extends nodefony.controller {

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

  /**
   *	@method htmlAction
   */
  htmlAction(name) {
    return this.renderResponse('<h1>' + name + '</h1>');
  }
};
            

nodefony

Rendering Twig Templates

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


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

module.exports = class demoController extends nodefony.controller {

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

  /**
   *	@method renderAction
   */
  renderAction(name) {
    return this.render('documentation-bundle:demo:doc.html.twig', {
      name: name
    });

  }
};
            
            

<h1> {{name}} </h1>
            

nodefony

Rendering JSON

URL : http://localhost:5151/json


  json:
    pattern:  /json
    defaults: {
      "controller": "demo-bundle:demo:json"
    }
              
module.exports = class demoController extends nodefony.controller {

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

    jsonAction (){
      return this.renderJson({
        foo:"bar",
        bar:"foo"
      });
    }
  };
            
Rendering Websocket

URL : ws://localhost:5151/websocket

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

module.exports = class demoController extends nodefony.controller {

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

  websocketAction (message){
    switch( this.method ){
      case "GET" :
        return this.render('demo-bundle:default:websocket.html.twig', {
          name:"websoket"
        });
      case "WEBSOCKET" :
        if (message){
          // log  message client in terminal
          this.log( 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.log( "send to client :" + mess , "info");
            i++
          }, 1000);

          setTimeout( () =>{
            clearInterval(id);
            // close reason , descripton
            this.context.close(1000, "nodefony controller close socket");
            id = null ;
          }, 10000);
          // event websocket close by client
          this.context.on("onClose", () =>{
            if (id){
              clearInterval(id);
            }
          });
        }
      break;
      default :
        throw new error(" method not allowed");
    }
  }
};
              

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
            

Local Recent Commits
    GitHub Issue Queue Activity