/*\ title: $:/core/modules/commands/server.js type: application/javascript module-type: command Serve tiddlers over http \*/ (function(){ /*jslint node: true, browser: true */ /*global $tw: false */ "use strict"; if(!$tw.browser) { var util = require("util"), fs = require("fs"), url = require("url"), path = require("path"), http = require("http"); } exports.info = { name: "server", synchronous: true }; /* A simple HTTP server with regexp-based routes */ function SimpleServer(options) { this.routes = options.routes || []; this.wiki = options.wiki; this.variables = options.variables || {}; } SimpleServer.prototype.set = function(obj) { var self = this; $tw.utils.each(obj,function(value,name) { self.variables[name] = value; }); }; SimpleServer.prototype.get = function(name) { return this.variables[name]; }; SimpleServer.prototype.addRoute = function(route) { this.routes.push(route); }; SimpleServer.prototype.findMatchingRoute = function(request,state) { var pathprefix = this.get("pathprefix") || ""; for(var t=0; t