Setup your own TiddlyPWA server on Raspberry Pi 5 (using cloudflare tunnel)

Disclaimer: I am not an expert, so please proceed with caution and back up your Raspberry Pi before attempting this. If you have more knowledge on the subject, please contribute and edit this post! I am using Windows, so your experience may vary if you’re on a different operating system.

TiddlyPWA — TiddlyWiki Storage & Sync Solution (packett.cool) is an awesome way to sync your wiki accross multiple devices, almost in real time. You can use Glitch to host a server for free, but Glitch apps are slow to wake up and have a limited storage capacity. In this post, we’ll see how to host our own server on a Raspberry Pi 5, and how to access this server from anywhere in the world.

Table of contents

  • Installing Raspberry Pi OS Lite on the RP5
  • Installing deno on the RP5
  • Setting up TiddlyPWA Sync Server
  • Automatically power cycle the Raspberry Pi once it gets stuck
  • Making your server public
  • Limitations of cloudflare tunnel

Installing Raspberry Pi OS Lite on the RP5

Note: I’m using a RP5 because that’s what I have, but you could probably use a Raspberry Pi Zero 2 W, or any similar alternative like Orange Pi & co

  1. Flash your sd card or external usb hard drive with Raspberry Pie imager. I used Raspberry Pi Os Lite (64-bit):

image

image

  1. Use OS customisation to enable SSH access to the pi:

image

Then Save.

When you turn on the pi, it should automatically connect to your local network and be accessible with PuTTY or any other SSH client. I also like to use WinSCP to browse the files on the pi more easily, but you don’t need it for this tutorial.

Installing deno on the RP5

Use PuTTY from the command line as usual, or create a shortcut for quick access:

  1. Create a shortcut on the desktop to putty.exe
  2. Rename it if you want
  3. Right click > Properties
  4. Modify the target similar to: "C:\Program Files\PuTTY\putty.exe" ******@raspberrypi -pw "******"
  5. Click OK

If your version of PuTTY does not support the pw parameter, you will need a public key.

Tip: to copy text on the PuTTY CLI, select the text with your mouse, then right click to paste.

Install deno on the pi:

curl -fsSL https://deno.land/install.sh | sh

Once installed, you need to add the installation directory of Deno in your system’s PATH. Open your shell configuration file:

nano ~/.bashrc

Add this to the end of the file:

export PATH="$HOME/.deno/bin:$PATH"

Save and close the file, then reload the configuration:

source ~/.bashrc

Check if deno is correctly installed:

deno --version

Setting up TiddlyPWA Sync Server

Create a folder for the server database:

sudo mkdir -p /var/db/tiddly/

Change the ownership of the directory to the user logged in (replace login with your username):

sudo chown login:login /var/db/tiddly/

Decide on an admin password and hash it :

deno run https://codeberg.org/valpackett/tiddlypwa/raw/branch/release/server/hash-admin-password.ts

Create a systemd service to run Deno automatically when the Raspberry Pi starts:

sudo nano /etc/systemd/system/tiddlypwa.service

Paste the following configuration in the file:

[Unit]
Description=TiddlyPWA Service
After=network.target

[Service]
# Use the appropriate user, e.g., `pi` if you are running this as the default Raspberry Pi user
User=pi

# Hash and salt setup during the installation of the tiddlywiki pwa server 
Environment="ADMIN_PASSWORD_HASH=......."
Environment="ADMIN_PASSWORD_SALT=......."
Environment="DB_PATH=/var/db/tiddly/pwa.db"
ExecStart=/home/pi/.deno/bin/deno run --unstable-broadcast-channel --allow-env --allow-read=/var/db/tiddly --allow-write=/var/db/tiddly --allow-net=:8000 https://codeberg.org/valpackett/tiddlypwa/raw/branch/release/server/run.ts
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
  • Replace /home/pi/.deno/bin/deno with the correct path to the Deno executable if different.
  • Change User=pi to the user under which you want the service to run.

After saving the service file, reload the systemd manager configuration and enable the service to start on boot:

sudo systemctl daemon-reload
sudo systemctl enable tiddlypwa.service

Start the service immediately to test it:

sudo systemctl start tiddlypwa.service

Check the status of the service to ensure it is running correctly:

sudo systemctl status tiddlypwa.service

This should run your Deno command every time your Raspberry Pi boots up. If there are any issues, you can check the logs using:

journalctl -u tiddlypwa.service -f

At this point, the TiddlyPWA server should be accessible on your local network by entering in a web browser the url : raspberrypi:8000.

Automatically power cycle the Raspberry Pi once it gets stuck

source: Running forever with the Raspberry Pi Hardware Watchdog | Diode™

Occasionally, the Pi may become unresponsive and freeze. To resolve this, you can manually power cycle the device by turning it off and then on again, or you can use the built-in hardware watchdog to reboot it automatically.

  1. Enable the hardware watchdog on your Pi and reboot
sudo su
echo 'dtparam=watchdog=on' >> /boot/config.txt
reboot
  1. Install the watchdog system service
sudo apt-get update
sudo apt-get install watchdog
  1. Configure the watchdog service
sudo su
echo 'watchdog-device = /dev/watchdog' >> /etc/watchdog.conf
echo 'watchdog-timeout = 15' >> /etc/watchdog.conf
echo 'max-load-1 = 24' >> /etc/watchdog.conf
echo 'interface = wlan0' >> /etc/watchdog.conf
  1. Enable the service
sudo systemctl enable watchdog
sudo systemctl start watchdog
sudo systemctl status watchdog

Now next time your Pi freezes or the WiFi interface wlan0 gets into trouble, the watchdog will restart it automatically after 15 seconds.

Making your server public

To make the server accessible outside of my local network, I used cloudflare tunnel. Note that this require a domain name. You can get a free or cheap domain name with one of these services:

You can also instead create a “Quick Tunnels” without domain name, but there are limits: Quick Tunnels | Cloudflare Zero Trust docs. The server won’t be able to handle more than 200 in-flight requests, which I guess should be enough for a small wiki. See TryCloudflare.

I followed this tutorial to set it up: Setting up a Cloudflare Tunnel on the Raspberry Pi - Pi My Life Up

Don’t forget to redirect users to https, otherwise tiddlywiki pwa will not function correctly: Always Use HTTPS | Cloudflare SSL/TLS docs

Limitations of cloudflare tunnel

If your network is unstable / or overloaded, the tunnel will not be able to connect to your deno server. This happened to me while I was syncing files with google drive, so be mindfull of that.

Cloudflare Tunnel seems to have a upload limit somewhere between 1.2MB and 1.4MB, at least on my network. I don’t know how to increase this limit, so try to keep the App File light (avoid uploading a lot of plugins all at once).

Conclusion

And that’s it! You should now be able to access to your own TiddlyPWA server from any device. Enjoy!

7 Likes

Another way I found to make the server reachable is using tailscale funnels in which case you won’t need a domain name.

1 Like