Hosting multiple tiddlywikis on express js

115 views
Skip to first unread message

Arlen Beiler

unread,
Jan 5, 2016, 10:25:34 AM1/5/16
to TiddlyWiki
Hello everyone,

Recently I decided to take another shot at trying to find some way to get TW5 easily usable for the way I do things (I use mediawiki installed on my local computer, believe it or not, which works great). I decided to try serving tiddlers from ExpressJS, since I wanted to run it off the same server that is already running everything else (ExpressJS with PHP CGI and file serving). And this time, I finally got it. An ExpressJS request handler that can host any number of Node Tiddlywikis from any number of locations on the filesystem. I even had it doing it dynamically, but then I figured that was more problem than adding one more line to your ExpressJS app.


Feel free to copy, use, reuse, etc. I've released my part as Public Domain, but it's so small it's barely copyrightable anyway. If server.js exposed it's listen handler, and excepted a state argument or something like that, I could just use it without copying out the code, I think.

Have a good day,
-Arlen

Jeremy Ruston

unread,
Jan 5, 2016, 10:28:54 AM1/5/16
to tiddl...@googlegroups.com
Hi Arlen

Great stuff, thanks for sharing.

If server.js exposed it's listen handler, and excepted a state argument or something like that, I could just use it without copying out the code, I think.

I’d be open to that kind of refactoring. Can you point at an example of app that does the right thing?

Best wishes

Jeremy.


Have a good day,
-Arlen


--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/CAJ1vdSRseJmXeBfJz_kHkYFDuixWnCx0YASNb10tKZ7z66Qu9Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Arlen Beiler

unread,
Jan 5, 2016, 2:38:17 PM1/5/16
to TiddlyWiki
In server.js, line ~146:

SimpleServer.prototype.listen = function(port,host) {
http.createServer(function(request, response){ /* request handler here */}).listen(port,host);
};

The function passed to http.createServer could just as easily be given to expressJS. The self/this variables would need to be figured out, but other than that it would work fine. In my implementation I put the function in a seperate property of SimpleServer.prototype and added a self variable as the first argument, and then passed it to app.use as server.requestHandler.bind(this,server); and in server.js ...bind(this,this);

That's one way of doing it, and although it seems like according to convention it shouldn't be part of the prototype, but that seems to work the best.

Arlen Beiler

unread,
Jan 7, 2016, 11:49:01 AM1/7/16
to TiddlyWiki
Hi Jeremy, 
Do you think you'll be able to do this in 5.1.10 yet? It would basically consist of taking the request handler function that is passed directly into http.createServer and putting it in it's own property on SimpleServer.prototype, changing "self" to "this", and calling it with http.createServer(this.requestHandler.bind(this))". 
Thanks, just wondering,
-Arlen

Jeremy Ruston

unread,
Jan 7, 2016, 11:54:53 AM1/7/16
to tiddl...@googlegroups.com
Hi Arlen

I’m afraid this is something for 5.1.11. I’m in the final stages of releasing 5.1.10 and so I don’t want to open up another surface area for testing.

As I mentioned, I’m keen to do some refactoring in this area. Besides interoperability with the wider Node.js world, I want to support non-HTTP transports (notably window.postMessage, which is used in the plugin library implementation). 

Best wishes

Jeremy


Reply all
Reply to author
Forward
0 new messages