diff --git a/Dragonfly.js b/Dragonfly.js index 7ec6ec6..ce1111d 100644 --- a/Dragonfly.js +++ b/Dragonfly.js @@ -93,7 +93,7 @@ class Dragonfly var tag = cluster.isMaster ? "M" : "S"; this.ptag = "[ " + tag + ":" + process.pid + " ] "; - this.Info( "Dragonfly ready.", Dragonfly.Visibility.VISIBLE ); + // this.Info( "Dragonfly ready.", Dragonfly.Visibility.VISIBLE ); } Debug( mesg, visibility ) diff --git a/net/AppDomain.js b/net/AppDomain.js index 2bffb3e..f90601a 100644 --- a/net/AppDomain.js +++ b/net/AppDomain.js @@ -57,6 +57,7 @@ function AppDomain( handler, port, cluster ) var http = require( "http" ); var server = http.createServer( function(req, res) { + res._hrtime = process.hrtime.bigint(); serverHandle( server, req, res, handler ); } ); diff --git a/net/WebFrame.js b/net/WebFrame.js index ab49f83..e78e8cb 100644 --- a/net/WebFrame.js +++ b/net/WebFrame.js @@ -169,7 +169,7 @@ class WebFrame this.HTTP.response.headers["Content-Length"] = data.length; this.HTTP.response.write( data ); this.HTTP.response.end(); - Dragonfly.Debug( "Result Planted" ); + Dragonfly.Debug( `Result Planted: ${process.hrtime.bigint() - this.HTTP.response.raw._hrtime}ns` ); } __storeCache( data, cache, ttl ) diff --git a/package.js b/package.js index b19a13d..9322c7a 100644 --- a/package.js +++ b/package.js @@ -13,7 +13,20 @@ Package.prototype.rootNS = function( name, path ) rootNS[ name ] = fs.realpathSync( path ) + "/"; }; -Package.prototype.load = function( _class, deCache ) +var _reload = function( e, filename ) +{ + if( this._lock ) + return; + this._lock = true; + + setTimeout( () => + { + global.Dragonfly.Info( `Change detected: ${this.src}, reloading` ); + global.X_SERVER_CLUSTER.worker.destroy(); + } , 200 ); +}; + +Package.prototype.load = function( _class ) { var fSep = _class.indexOf( "." ); var nsdomain = _class.substr( 0, fSep ); @@ -21,14 +34,16 @@ Package.prototype.load = function( _class, deCache ) var file = rootNS[ nsdomain ] + _class; - var lClass = require( file ); - // TODO: Implements filewatcher - - if( deCache ) + if( global.debug && global.X_SERVER_CLUSTER ) { - delete require.cache[ require.resolve( file ) ]; + var src = require.resolve( file ); + if(!( src in require.cache )) + { + fs.watch( src, _reload.bind({ "src": src }) ); + } } - return lClass; + + return require( file ); }; global.botanLoader = new Package(); diff --git a/system/PageCache.js b/system/PageCache.js index 8230336..aa40325 100644 --- a/system/PageCache.js +++ b/system/PageCache.js @@ -50,7 +50,7 @@ class PageCache , headers: { "Content-Length": res.headers[ "Content-Length" ] , "Content-Type": res.headers[ "Content-Type" ] - , "X-Cache-Expires": new Date( expires ) + , "X-Cache-Expirls": new Date( expires ).toISOString() } , statusCode: res.statusCode , ttl: expires @@ -87,18 +87,19 @@ class PageCache if( url in store ) { - Dragonfly.Info( - "[C] " - + ( req.headers[ "x-forwarded-for" ] || req.connection.remoteAddress ) + " " - + req.method + ": " + encodeURI( url ) - + " - " + req.headers["user-agent"] - , Dragonfly.Visibility.VISIBLE - ); - var c = store[ url ]; res.writeHead( c.statusCode, c.headers ); res.end( c.data ); + Dragonfly.Info( + "[C] " + + ( req.headers[ "x-forwarded-for" ] || req.connection.remoteAddress ) + " " + + req.method + ": " + url + + " - " + req.headers["user-agent"] + + ` in ${process.hrtime.bigint() - res._hrtime}ns` + , Dragonfly.Visibility.VISIBLE + ); + return true; }