1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-18 11:29:55 +00:00

Switch to "dash" separated parameter names

This commit is contained in:
Jermolene 2018-07-01 14:08:23 +01:00
parent cc2f5e0d11
commit 30ce7ea49a
6 changed files with 60 additions and 32 deletions

View File

@ -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 [<name>=<value>]...
```
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")

View File

@ -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 <port> <roottiddler> <rendertype> <servetype> <username> <password> <host> <pathprefix>
--server <port> <root-tiddler> <root-render-type> <root-serve-type> <username> <password> <host> <path-prefix> <debug-level>
```
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
```

View File

@ -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");
}
/*

View File

@ -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");
};

View File

@ -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");

View File

@ -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<this.routes.length; t++) {
var potentialRoute = this.routes[t],
pathRegExp = potentialRoute.path,
@ -185,7 +189,7 @@ Server.prototype.requestHandler = function(request,response) {
// Find the route that matches this path
var route = self.findMatchingRoute(request,state);
// Optionally output debug info
if(self.get("debuglevel") !== "none") {
if(self.get("debug-level") !== "none") {
console.log("Request path:",JSON.stringify(state.urlInfo));
console.log("Request headers:",JSON.stringify(request.headers));
console.log("authenticatedUsername:",state.authenticatedUsername);