Invoke hook when server starts (#3024)

* Invoke hook when server starts

Invokes the `th-server-command-start` hook when the server is started, with the server object as the parameter. This allows adding a WebSocket listener to the server.

* Return the HTTP server from the listen function

Returns the node HTTP server created in the listen function to allow extension

* Add node HTTP server to server-command-start hook

* Change hook to post start in case we add a pre-start hook

* Create Hook__th-server-command-post-start.tid
This commit is contained in:
Arlen22
2018-04-10 21:55:54 +01:00
committed by Jeremy Ruston
parent 3af0487f29
commit 2163302190
2 changed files with 21 additions and 2 deletions
+3 -2
View File
@@ -143,7 +143,7 @@ SimpleServer.prototype.requestHandler = function(request,response) {
};
SimpleServer.prototype.listen = function(port,host) {
http.createServer(this.requestHandler.bind(this)).listen(port,host);
return http.createServer(this.requestHandler.bind(this)).listen(port,host);
};
var Command = function(params,commander,callback) {
@@ -302,13 +302,14 @@ Command.prototype.execute = function() {
password: password,
pathprefix: pathprefix
});
this.server.listen(port,host);
var nodeServer = this.server.listen(port,host);
$tw.utils.log("Serving on " + host + ":" + port,"brown/orange");
$tw.utils.log("(press ctrl-C to exit)","red");
// Warn if required plugins are missing
if(!$tw.wiki.getTiddler("$:/plugins/tiddlywiki/tiddlyweb") || !$tw.wiki.getTiddler("$:/plugins/tiddlywiki/filesystem")) {
$tw.utils.warning("Warning: Plugins required for client-server operation (\"tiddlywiki/filesystem\" and \"tiddlywiki/tiddlyweb\") are missing from tiddlywiki.info file");
}
$tw.hooks.invokeHook('th-server-command-post-start', this.server, nodeServer);
return null;
};