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!

9 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

Hi Val,
Great step by step instruction on setting up TiddlyPWA on Raspberry. I managed to installed this on Raspberry 3 and was able to access the server on my browser (TiddlyPWA Sync Server Control Panel) and created a new wiki. However when I tried to upload using the uploadApp, this error message appeared “Upload error: TypeError: Failed to fetch” . I am a newbie on raspberry and PWA. Any suggestion what might be the issue here?

A few things to check that might be causing the issue:

  • Are you accessing your TiddlyPWA instance using a dedicated domain name or just the local network address?
    If you’re using a local address like http://raspberrypi:8000 or http://192.168.x.x:8000, some browsers might block uploads due to security restrictions. If possible, try setting up a custom domain (e.g., https://yourwiki.example.com) and ensure it’s correctly configured to point to your Raspberry Pi. Without a proper domain name, your browser might block certain actions like file uploads.

  • Is there enough storage available on your Raspberry Pi 3?
    If the storage is full, the server won’t be able to process new uploads.

  • Is the Raspberry Pi 3 powerful enough to handle the Deno server?
    Check if the TiddlyPWA service is running correctly by using:

    sudo systemctl status tiddlypwa.service
    

    If you see any issues, check the logs for more details:

    journalctl -u tiddlypwa.service -f
    
  • Is HTTPS properly configured?
    Some browsers block requests due to cross-origin restrictions or missing HTTPS. If you’re accessing the control panel over HTTPS, make sure the upload endpoint is also secured.

  • Are the database directory permissions set correctly?
    If the database directory isn’t writable, uploads may fail. Verify the directory’s paths and permissions.

If none of these steps resolve the issue, consider opening an issue on Codeberg:
:link: https://codeberg.org/valpackett/tiddlypwa/issues

1 Like

Telumire, thanks for the comprehensive troubleshooting:

I am using local http://192.168.x.x:8000. I do not know how to set up a custom domain for my local raspberry server.

There is plenty of storage, using 32GB microSD with Raspberry Lite and Deno on it only.

No issue with status tiddlypwa.service

I have configured the browser to accept http on local network

No problem. Can touch the DB directory with a txt file.

There is one occasion when I was able to sync and refresh with content size value but no App size value…but cannot repeat the process with upload of App wiki.

Any other further suggestion is appreciated. I have tried Glitch and I think TiddlyPWA is really great.

Tiddlywiki PWA require https to works: TiddlyPWA — TiddlyWiki Storage & Sync Solution

You can test it by accessing the endpoint: http://raspberrypi:8000/tid.dly
You will see an error code :

{
  "error": "EPROTO"
}

As a workaround, you can upload to your wiki with localhost, by opening TiddlyPWA — TiddlyWiki Storage & Sync Solution with a web browser running on your pi:

It’s fine if you use it on your local network, but you need to use https if you want your server to be public.

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