Skip to content

Commit

Permalink
Remove unneeded server extensions
Browse files Browse the repository at this point in the history
And fix up the response timing
  • Loading branch information
Jermolene committed Mar 10, 2024
1 parent e4f3b41 commit 5a0ddeb
Showing 1 changed file with 6 additions and 22 deletions.
28 changes: 6 additions & 22 deletions core/modules/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@ A simple HTTP server with regexp-based routes
options: variables - optional hashmap of variables to set (a misnomer - they are really constant parameters)
routes - optional array of routes to use
wiki - reference to wiki object
verbose - boolean
*/
function Server(options) {
var self = this;
this.routes = options.routes || [];
this.authenticators = options.authenticators || [];
this.wiki = options.wiki;
this.boot = options.boot || $tw.boot;
this.verbose = !!options.verbose;
// Initialise the variables
this.variables = $tw.utils.extend({},this.defaultVariables);
if(options.variables) {
Expand All @@ -45,14 +43,6 @@ function Server(options) {
}
}
}
// Register server extensions
this.extensions = [];
$tw.modules.forEachModuleOfType("server-extension",function(title,exports) {
var extension = new exports.Extension(self);
self.extensions.push(extension);
});
// Initialise server extensions
this.invokeExtensionHook("server-start-initialisation");
// Setup the default required plugins
this.requiredPlugins = this.get("required-plugins").split(',');
// Initialise CSRF
Expand Down Expand Up @@ -105,16 +95,8 @@ function Server(options) {
this.servername = $tw.utils.transliterateToSafeASCII(this.get("server-name") || this.wiki.getTiddlerText("$:/SiteTitle") || "TiddlyWiki5");
this.boot.origin = this.get("origin")? this.get("origin"): this.protocol+"://"+this.get("host")+":"+this.get("port");
this.boot.pathPrefix = this.get("path-prefix") || "";
// Complete initialisation of server extensions
this.invokeExtensionHook("server-completed-initialisation");
}

Server.prototype.invokeExtensionHook = function(hookName) {
$tw.utils.each(this.extensions,function(extension) {
extension.hook(hookName);
});
};

/*
Send a response to the client. This method checks if the response must be sent
or if the client alrady has the data cached. If that's the case only a 304
Expand Down Expand Up @@ -473,10 +455,12 @@ Server.prototype.listen = function(port,host,prefix) {
}
// Create the server
var server = this.transport.createServer(this.listenOptions || {},function(request,response,options) {
var start = new Date().getTime()
response.on("finish",function() {
// console.log("Request",request.method,request.url,(new Date().getTime()) - start);
});
if(self.get("debug-level") !== "none") {
var start = $tw.utils.timer();
response.on("finish",function() {
console.log("Response tim:",request.method,request.url,$tw.utils.timer() - start);
});
}
self.requestHandler(request,response,options);
});
// Display the port number after we've started listening (the port number might have been specified as zero, in which case we will get an assigned port)
Expand Down

0 comments on commit 5a0ddeb

Please sign in to comment.