

Nodefony 6.11.0
- Servers
- Front Proxy NGINX
- Production Mode PM2
- Nodefony sessions
- Web application firewall (WAF)
- Orm
- Realtime
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 ( Configurations framework )
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
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 :
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 extends nodefony.Controller {
constructor(container, context) {
super(container, context);
}
/**
* @method htmlAction
*/
htmlAction(name) {
return this.renderResponse('<h1>' + name + '</h1>');
}
}
nodefony
URL :
http://localhost:5151/doc/demo/render/nodefony
documentation-demo-render:
pattern : /doc/demo/render/{name}
defaults: {
controller : "documentation:demo:render",
"name" : "nodefony"
}
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>
URL :
http://localhost:5151/json
json:
pattern: /json
defaults: {
"controller": "demo-bundle:demo:json"
}
class demoController extends nodefony.Controller {
constructor (container, context){
super(container, context);
}
jsonAction (){
return this.renderJson({
foo:"bar",
bar:"foo"
});
}
}
URL :
ws://localhost:5151/websocket
websoket:
pattern: /websocket
defaults: {
"controller": "demo-bundle:demo:websocket"
}
requirements:
method:
- GET
- WEBSOCKET
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