1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-01-11 09:50:27 +00:00

Extend server command to allow a path prefix

Thereby making the number of parameters to the command ludicrous
This commit is contained in:
Jermolene 2014-06-13 14:44:34 +01:00
parent 4238af2a40
commit eee3a0cf8e
3 changed files with 33 additions and 4 deletions

View File

@ -6,7 +6,7 @@ The server built in to TiddlyWiki5 is very simple. Although compatible with Tidd
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`.
```
--server <port> <roottiddler> <rendertype> <servetype> <username> <password> <host>
--server <port> <roottiddler> <rendertype> <servetype> <username> <password> <host> <pathprefix>
```
The parameters are:
@ -18,6 +18,7 @@ The parameters are:
* ''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
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.

View File

@ -50,10 +50,22 @@ SimpleServer.prototype.addRoute = function(route) {
};
SimpleServer.prototype.findMatchingRoute = function(request,state) {
var pathprefix = this.get("pathprefix") || "";
for(var t=0; t<this.routes.length; t++) {
var potentialRoute = this.routes[t],
pathRegExp = potentialRoute.path,
match = potentialRoute.path.exec(state.urlInfo.pathname);
pathname = state.urlInfo.pathname,
match;
if(pathprefix) {
if(pathname.substr(0,pathprefix.length) === pathprefix) {
pathname = pathname.substr(pathprefix.length);
match = potentialRoute.path.exec(pathname);
} else {
match = false;
}
} else {
match = potentialRoute.path.exec(pathname);
}
if(match && request.method === potentialRoute.method) {
state.params = [];
for(var p=1; p<match.length; p++) {
@ -272,13 +284,15 @@ Command.prototype.execute = function() {
serveType = this.params[3] || "text/html",
username = this.params[4],
password = this.params[5],
host = this.params[6] || "127.0.0.1";
host = this.params[6] || "127.0.0.1",
pathprefix = this.params[7];
this.server.set({
rootTiddler: rootTiddler,
renderType: renderType,
serveType: serveType,
username: username,
password: password
password: password,
pathprefix: pathprefix
});
this.server.listen(port,host);
console.log("Serving on " + host + ":" + port);

View File

@ -0,0 +1,14 @@
created: 20140613133627669
modified: 20140613134313770
tags: howto
title: Using a custom path prefix with the client-server edition
type: text/vnd.tiddlywiki
By default, when running [[TiddlyWiki on Node.js]], the server exposes the wiki at the URI formed from the protocol, host and port - for example, `http://127.0.0.1:8080/`.
There are two steps to running the wiki at a custom path like `http://127.0.0.1:8080/path/to/my/wiki/`:
# Configure the server by passing `/path/to/my/wiki` as the ''pathprefix'' argument of the ServerCommand
# Configure the client by creating a tiddler called ''$:/config/tiddlyweb/host'' that contains `$protocol$//$host$/path/to/my/wiki/`