Clean Server: run your app anywhere

You need Clean Server when you put your app online. It runs your compiled app, serves HTTP, talks to your database and keeps every request inside the WebAssembly sandbox. Nothing else to install.

command clean-server
See it

One command to run an app

Point Clean Server at the .wasm file the compiler produced and give it a database. That's the whole setup.

Your app never holds a database password in its code or a network socket. It asks Clean Server, and Clean Server does the work.

Terminal
# Install once
cleen server install

# Run on your machine with SQLite
clean-server app.wasm --database "sqlite://app.db?mode=rwc"

# Run in production with PostgreSQL
clean-server app.wasm --port 3001 --host 127.0.0.1 \
  --database "postgres://user:pass@localhost/app"
What it gives your app

Everything outside the sandbox

HTTP

Routes, requests, responses, sessions and login for the endpoints your app declares.

Databases

SQLite, PostgreSQL and MySQL with a connection pool. Switch by changing one URL.

Files and network

File access, outgoing HTTP calls, time and randomness, only when your app asks.

Crypto

Password hashing, tokens and hashes run natively, at full speed.

Memory limits

Choose how much memory each app instance may use, from 8 MB to 512 MB.

One small program

No Node, no Docker, no runtime to match. Linux, macOS and Windows, on x64 and ARM.

Tutorial · 10 minutes

Put an app online on a Linux server

The same setup that runs this website. You need a Linux server with nginx and your compiled app.wasm.

1

Download Clean Server

Get the build for your server from the releases page. On an ARM server, use linux-arm64.

Server terminal
mkdir -p /opt/myapp/bin
curl -fsSL https://github.com/Ivan-Pasco/clean-server-old/releases/latest/download/clean-server-linux-x64.tar.gz | tar -xz -C /opt/myapp/bin
/opt/myapp/bin/clean-server --version
2

Copy your app

Build on your machine, then copy the result. If your app has pages, copy build-manifest.json next to app.wasm too.

Your terminal
cln compile main.cln -o app.wasm --plugins
scp app.wasm build-manifest.json you@server:/opt/myapp/
3

Keep it running with systemd

systemd starts the app on boot and restarts it if it stops. The database URL lives in /opt/myapp/.env as DATABASE_URL=....

/etc/systemd/system/myapp.service
[Unit]
Description=My Clean app
After=network.target

[Service]
WorkingDirectory=/opt/myapp
EnvironmentFile=/opt/myapp/.env
ExecStart=/opt/myapp/bin/clean-server /opt/myapp/app.wasm --port 3001 --host 127.0.0.1 --memory-tier large
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target
Server terminal
systemctl daemon-reload
systemctl enable --now myapp
4

Put nginx in front

nginx handles HTTPS and sends requests to Clean Server, which only listens on the local machine.

/etc/nginx/sites-available/myapp
server {
    server_name myapp.example.com;

    location / {
        proxy_pass http://127.0.0.1:3001;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Enable the site, reload nginx, and add HTTPS with Certbot. Your app is live.

Reference

Options

OptionWhat it does
--portPort to listen on. Default: the port your app declares, else 3000
--hostAddress to bind to. Use 127.0.0.1 behind a proxy
--databaseDatabase URL: sqlite://, postgres:// or mysql://. Also read from DATABASE_URL
--db-pool-sizeDatabase connections to keep open. Default 10
--memory-tierMemory per instance: minimal 8 MB, standard 32 MB, large 128 MB, xlarge 512 MB
--body-limitLargest request body in MB. Default 10
--no-corsTurn off CORS headers
--verboseLog more detail
Questions

Common questions

Do I need Docker?

No. Clean Server is a single program. You can still run it in a container if that's how you deploy everything else.

Which systems does it run on?

Linux, macOS and Windows on x64, plus Linux and macOS on ARM. Downloads are on the releases page, or run cleen server install.

Can I run more than one app on a server?

Yes. Run one Clean Server per app on its own port, and let nginx route each domain to the right one.

How do I update my app?

Copy the new app.wasm and restart the service with systemctl restart myapp.

Rather not run a server?

Clean Cloud hosts Clean apps with a database, domain and email included.

Copied!