TIP: Loading TiddlyWiki in CGI on an HTTP Server

TIP: Loading TiddlyWiki in CGI on an HTTP Server

This tip probably serves no practical purpose. Just a pointless experiment.

CGI is the most primitive method for executing code on an HTTP server.

The CGI method does not continuously consume server resources.

I recently added CGI functionality to a Python project and casually tested whether TiddlyWiki could run under CGI. Below are the results of that attempt.

TiddlyWiki can only be loaded, not edited. Since all API access in my own project uses POST requests, it was straightforward to port it to CGI.

i thunk the nix/shell version of tw.bat

might be
tw.sh

cat tw.sh


echo Content-Type: text/html; charset=utf-8
echo


node tw.js Wikis/empty --listen

has any one else tested tomzheng/tiddlywiki-cgi?
how should i use it ? (what steps)

i tried cloning TiddlyWiki/TiddlyWiki5 and
copying files in tomzheng/tiddlywiki-cgi into the tw5 clone
(is that reasonable approach??)

What is your purpose for using CGI? Since my server runs Go, I didn’t want to set up another Node server, so I opted for CGI.

Refer to my README:

First, install Node.

Next, start an HTTP server that supports CGI.

After downloading the TiddlyWiki5 code repository, place its directories and files into the CGI directory of your CGI-enabled HTTP server.

Then, follow the path to overwrite server.js.

Next, place your modified tw.sh file into the CGI directory.

Then, place tw.js into the CGI directory.

Finally, access your tw.sh file via your browser.

as you say

but also the Hand-powered crank like
way cgi works has its own appeal !

ahh! :bulb:
this was the source of my confusion

( core-server/server /server.js
vs
core/modules/server /server.js)

                  https://.github.com/TiddlyWiki/TiddlyWiki5/tree/master/core/modules

           https://.codeberg.org/tomzheng/tiddlywiki-cgi/src/branch/main/core/modules/server /server.js

                   https://.github.com/TiddlyWiki/TiddlyWiki5/tree/master/core-server/server /server.js

My version is 5.2.8 pre-release.

It seems the file location has changed in the new version.

So you’ll need to manually modify this file.

Refer to my code.

// Display the port number after we've started listening (the port number might have been specified as zero, in which case we will get an assigned port)
	server.on("listening",function() {
		var address = server.address(),
			url = self.protocol + "://" + (address.family === "IPv6" ? "[" + address.address + "]" : address.address) + ":" + address.port + prefix;
		$tw.utils.log("Serving on " + url,"brown/orange");
		$tw.utils.log("(press ctrl-C to exit)","red");
	});
	
	
/////////////////////////////////////////////////////// changed /////////////////////////////////////////////////
	var text = $tw.wiki.renderTiddler("text/plain","$:/core/save/all");
	console.log(text);

	result='';
	
	// Listen
	//return server.listen(port,host);
	return result;

/////////////////////////////////////////////////////// changed end /////////////////////////////////////////////////
};

This section is near the end of the document.