From 30ce7ea49a49664740386b9bd3fc2d6316546ced Mon Sep 17 00:00:00 2001 From: Jermolene Date: Sun, 1 Jul 2018 14:08:23 +0100 Subject: [PATCH] Switch to "dash" separated parameter names --- core/language/en-GB/Help/listen.tid | 29 +++++++++++++++++++ core/language/en-GB/Help/server.tid | 21 ++++++-------- core/modules/server/authenticators/header.js | 2 +- core/modules/server/routes/get-index.js | 4 +-- .../modules/server/routes/get-tiddler-html.js | 14 ++++----- core/modules/server/server.js | 22 ++++++++------ 6 files changed, 60 insertions(+), 32 deletions(-) create mode 100644 core/language/en-GB/Help/listen.tid diff --git a/core/language/en-GB/Help/listen.tid b/core/language/en-GB/Help/listen.tid new file mode 100644 index 000000000..d27d3eedc --- /dev/null +++ b/core/language/en-GB/Help/listen.tid @@ -0,0 +1,29 @@ +title: $:/language/Help/listen +description: Provides an HTTP server interface to TiddlyWiki + +Serves a wiki over HTTP. + +The listen command uses NamedCommandParameters: + +``` +--listen [=]... +``` + +All parameters are optional with safe defaults, and can be specified in any order. The recognised parameters are: + +* ''host'' - optional hostname to serve from (defaults to "127.0.0.1" aka "localhost") +* ''path-prefix'' - optional prefix for paths +* ''port'' - port number on which to listen; non-numeric values are interpreted as a system environment variable from which the port number is extracted (defaults to "8080") +* ''credentials'' - pathname of credentials CSV file (relative to wiki folder) +* ''username'' - the default username for signing edits +* ''password'' - optional password for basic authentication +* ''authenticated-user-header'' - optional name of header to be used for trusted authentication +* ''readers'' - comma separated list of principals allowed to write to this wiki +* ''writers'' - comma separated list of principals allowed to read from this wiki +* ''csrf-disable'' - set to "yes" to disable CSRF checks (defaults to "no") +* ''root-tiddler'' - the tiddler to serve at the root (defaults to "$:/core/save/all") +* ''root-render-type'' - the content type to which the root tiddler should be rendered (defaults to "text/plain") +* ''root-serve-type'' - the content type with which the root tiddler should be served (defaults to "text/html") +* ''tls-cert'' - pathname of TLS certificate file (relative to wiki folder) +* ''tls-key'' - pathname of TLS key file (relative to wiki folder) +* ''debug-level'' - optional debug level; set to "debug" to view request details (defaults to "none") diff --git a/core/language/en-GB/Help/server.tid b/core/language/en-GB/Help/server.tid index 3f0adbe24..8c5f932b4 100644 --- a/core/language/en-GB/Help/server.tid +++ b/core/language/en-GB/Help/server.tid @@ -1,27 +1,25 @@ title: $:/language/Help/server -description: Provides an HTTP server interface to TiddlyWiki +description: Provides an HTTP server interface to TiddlyWiki (deprecated in favour of the new listen command) -The server built in to TiddlyWiki5 is very simple. Although compatible with TiddlyWeb it doesn't support many of the features needed for robust Internet-facing usage. - -At the root, it serves a rendering of a specified tiddler. Away from the root, it serves individual tiddlers encoded in JSON, and supports the basic HTTP operations for `GET`, `PUT` and `DELETE`. +Legacy command to serve a wiki over HTTP. ``` ---server +--server ``` The parameters are: * ''port'' - port number on which to listen; non-numeric values are interpreted as a system environment variable from which the port number is extracted (defaults to "8080") -* ''roottiddler'' - the tiddler to serve at the root (defaults to "$:/core/save/all") -* ''rendertype'' - the content type to which the root tiddler should be rendered (defaults to "text/plain") -* ''servetype'' - the content type with which the root tiddler should be served (defaults to "text/html") +* ''root-tiddler'' - the tiddler to serve at the root (defaults to "$:/core/save/all") +* ''root-render-type'' - the content type to which the root tiddler should be rendered (defaults to "text/plain") +* ''rooot-serve-type'' - the content type with which the root tiddler should be served (defaults to "text/html") * ''username'' - the default username for signing edits * ''password'' - optional password for basic authentication * ''host'' - optional hostname to serve from (defaults to "127.0.0.1" aka "localhost") -* ''pathprefix'' - optional prefix for paths -* ''debuglevel'' - optional debug level; set to "debug" to view request details (defaults to "none") +* ''path-prefix'' - optional prefix for paths +* ''debug-level'' - optional debug level; set to "debug" to view request details (defaults to "none") -If the password parameter is specified then the browser will prompt the user for the username and password. Note that the password is transmitted in plain text so this implementation isn't suitable for general use. +If the password parameter is specified then the browser will prompt the user for the username and password. Note that the password is transmitted in plain text so this implementation should only be used on a trusted network or over HTTPS. For example: @@ -37,7 +35,6 @@ The username and password can be specified as empty strings if you need to set t To run multiple TiddlyWiki servers at the same time you'll need to put each one on a different port. It can be useful to use an environment variable to pass the port number to the Node.js process. This example references an environment variable called "MY_PORT_NUMBER": - ``` --server MY_PORT_NUMBER $:/core/save/all text/plain text/html MyUserName passw0rd ``` diff --git a/core/modules/server/authenticators/header.js b/core/modules/server/authenticators/header.js index 4b17cc468..d202ad607 100644 --- a/core/modules/server/authenticators/header.js +++ b/core/modules/server/authenticators/header.js @@ -14,7 +14,7 @@ Authenticator for trusted header authentication function HeaderAuthenticator(server) { this.server = server; - this.header = server.get("authenticateduserheader"); + this.header = server.get("authenticated-user-header"); } /* diff --git a/core/modules/server/routes/get-index.js b/core/modules/server/routes/get-index.js index bde3fb67c..603103c6b 100644 --- a/core/modules/server/routes/get-index.js +++ b/core/modules/server/routes/get-index.js @@ -17,8 +17,8 @@ exports.method = "GET"; exports.path = /^\/$/; exports.handler = function(request,response,state) { - response.writeHead(200, {"Content-Type": state.server.get("servetype")}); - var text = state.wiki.renderTiddler(state.server.get("rendertype"),state.server.get("roottiddler")); + response.writeHead(200, {"Content-Type": state.server.get("root-serve-type")}); + var text = state.wiki.renderTiddler(state.server.get("root-render-type"),state.server.get("root-tiddler")); response.end(text,"utf8"); }; diff --git a/core/modules/server/routes/get-tiddler-html.js b/core/modules/server/routes/get-tiddler-html.js index 218dbae66..f9ff5267c 100644 --- a/core/modules/server/routes/get-tiddler-html.js +++ b/core/modules/server/routes/get-tiddler-html.js @@ -20,18 +20,16 @@ exports.handler = function(request,response,state) { var title = decodeURIComponent(state.params[0]), tiddler = state.wiki.getTiddler(title); if(tiddler) { - var outputType,serveType,template; + var renderType,template; // Render ordinary tiddlers as HTML, and system tiddlers in plain text if(state.wiki.isSystemTiddler(title)) { - outputType = "text/plain"; - serveType = "text/plain"; - template = "$:/core/templates/wikified-tiddler"; + renderType = state.server.get("system-tiddler-render-type"); + template = state.server.get("system-tiddler-template"); } else { - outputType = "text/html"; - serveType = "text/html"; - template = "$:/core/templates/server/static.tiddler.html"; + renderType = state.server.get("tiddler-render-type"); + template = state.server.get("tiddler-template"); } - var text = state.wiki.renderTiddler(outputType,template,{variables: {currentTiddler: title}}); + var text = state.wiki.renderTiddler(renderType,template,{variables: {currentTiddler: title}}); // Naughty not to set a content-type, but it's the easiest way to ensure the browser will see HTML pages as HTML, and accept plain text tiddlers as CSS or JS response.writeHead(200); response.end(text,"utf8"); diff --git a/core/modules/server/server.js b/core/modules/server/server.js index 2233f1803..0ebbcfcb2 100644 --- a/core/modules/server/server.js +++ b/core/modules/server/server.js @@ -42,7 +42,7 @@ function Server(options) { } $tw.utils.extend({},this.defaultVariables,options.variables); // Initialise CSRF - this.csrfDisable = this.get("csrfdisable") === "yes"; + this.csrfDisable = this.get("csrf-disable") === "yes"; // Initialise authorization var authorizedUserName = (this.get("username") && this.get("password")) ? this.get("username") : "(anon)"; this.authorizationPrincipals = { @@ -62,8 +62,8 @@ function Server(options) { // Initialise the http vs https this.listenOptions = {}; this.protocol = "http"; - var tlsKeyFilepath = this.get("tlskey"), - tlsCertFilepath = this.get("tlscert"); + var tlsKeyFilepath = this.get("tls-key"), + tlsCertFilepath = this.get("tls-cert"); if(tlsCertFilepath && tlsKeyFilepath) { this.listenOptions.key = fs.readFileSync(path.resolve($tw.boot.wikiPath,tlsKeyFilepath),"utf8"); this.listenOptions.cert = fs.readFileSync(path.resolve($tw.boot.wikiPath,tlsCertFilepath),"utf8"); @@ -75,10 +75,14 @@ function Server(options) { Server.prototype.defaultVariables = { port: "8080", host: "127.0.0.1", - roottiddler: "$:/core/save/all", - rendertype: "text/plain", - servetype: "text/html", - debuglevel: "none" + "root-tiddler": "$:/core/save/all", + "root-render-type": "text/plain", + "root-serve-type": "text/html", + "tiddler-render-type": "text/html", + "tiddlertemplate": "$:/core/templates/server/static.tiddler.html", + "system-tiddler-render-type": "text/plain", + "system-tiddler-template": "$:/core/templates/wikified-tiddler", + "debug-level": "none" }; Server.prototype.get = function(name) { @@ -102,7 +106,7 @@ Server.prototype.addAuthenticator = function(AuthenticatorClass) { }; Server.prototype.findMatchingRoute = function(request,state) { - var pathprefix = this.get("pathprefix") || ""; + var pathprefix = this.get("path-prefix") || ""; for(var t=0; t