Toolatra is a modern Sinatra-like micro web framework for writing HTTP Tcl web applications.
app.tcl code:
#!/usr/bin/env tclsh package require Toolatra get / { render {Hello world!} } get /+name { render "Hello, [dict get $params name]!" } post / { if {$rawData != {}} { render "Hello, $rawData (via POST request)!" } else { render {Hello world (via POST request)!} } } run
How to run:
$ tclsh8.5 app.tcl
The app will be running at http://localhost:5050
Both the current and the previous version of Cat Language Translator are written 100% in Tcl and Toolatra. The source code of the first version can be found here: https://github.com/timkoi/catlanguage-web
First, specify the port where Toolatra's HTTP server shall be running. In the application, specify the port as the argument to the run command, like this:
run 5056
Replace 5056 with your preferred port number.
Now, create a user and a systemd service for the web app:
$ sudo useradd -M -N toolatrarunner $ sudo chsh -s /sbin/nologin toolatrarunner $ sudo mkdir -pv /srv/mytoolatraapp $ mv -v * /srv/mytoolatraapp $ sudo chown -v -R toolatrarunner:users /srv/mytoolatraapp $ cat >> /etc/systemd/system/mytoolatraapp.service << EOF [Unit] Description=My Toolatra web app After=httpd.service [Service] Type=simple ExecStart=/bin/sh -c "cd /srv/mytoolatraapp && LC_ALL=C /usr/bin/env tclsh app.tcl" User=toolatrarunner [Install] WantedBy=multi-user.target EOF $ sudo systemctl enable mytoolatraapp $ sudo systemctl start mytoolatraapp
Obviously, replace mytoolatraapp with the short name of your Toolatra web app.
Now create a reverse proxy with Apache:
$ sudo sh $ echo 'ProxyPreserveHost On' >> /etc/httpd/conf/httpd.conf $ echo 'ProxyPass /mytoolatraapp/ http://localhost:5056/' >> /etc/httpd/conf/httpd.conf $ echo 'ProxyPassReverse /mytoolatraapp/ http://localhost:5056/' >> /etc/httpd/conf/httpd.conf $ systemctl restart httpd $ exit
Obviously, replace 5056 with the port you've specified and mytoolatraapp with the name of your web app.
That's it!