Skip to content

Bare metal

Hyperterse is a standalone binary, so you can run it directly on servers without containers. It requires no external dependencies, and is as simple as dropping the binary on the server and running it.

  1. Export bundle

    Terminal window
    hyperterse export -f my-query-gateway.terse -o dist
  2. Transfer to server

    Terminal window
    scp -r dist/my-query-gateway user@server:/opt/my-query-gateway
  3. Run on server

    Terminal window
    ssh user@server
    cd /opt/my-query-gateway
    export DATABASE_URL="postgresql://user:pass@localhost:5432/app"
    ./my-query-gateway

Since Hyperterse is a standalone binary, you can run it as a system service.

  1. Create the systemd service file

    /etc/systemd/system/my-query-gateway.service
    [Unit]
    Description=My Query Gateway
    After=network.target postgresql.service
    Wants=postgresql.service
    [Service]
    Type=simple
    User=hyperterse
    Group=hyperterse
    WorkingDirectory=/opt/my-query-gateway
    EnvironmentFile=/opt/my-query-gateway/.env
    ExecStart=/opt/my-query-gateway/my-query-gateway
    Restart=always
    RestartSec=5
    # Security hardening
    NoNewPrivileges=true
    ProtectSystem=strict
    ProtectHome=true
    PrivateTmp=true
    ReadOnlyPaths=/
    [Install]
    WantedBy=multi-user.target
  2. Create the environment file

    /opt/my-query-gateway/.env
    DATABASE_URL=postgresql://user:pass@localhost:5432/app
    REDIS_URL=redis://localhost:6379/0
  3. Enable and start the service

    Terminal window
    # Create user
    sudo useradd -r -s /bin/false hyperterse
    # Set permissions
    sudo chown -R hyperterse:hyperterse /opt/my-query-gateway
    # Enable and start
    sudo systemctl enable my-query-gateway
    sudo systemctl start my-query-gateway
    # Check status
    sudo systemctl status my-query-gateway

You can use a process manager like PM2 to start and manage the service.

  1. Install PM2

    Terminal window
    npm install -g pm2
  2. Start the service

    Terminal window
    pm2 start /opt/my-query-gateway/my-query-gateway
  3. Save configuration and enable startup

    Terminal window
    pm2 save
    pm2 startup

You can also use Nginx to reverse proxy the service.

  1. Create the Nginx configuration file

    /etc/nginx/sites-available/my-query-gateway
    upstream hyperterse {
    server 127.0.0.1:8080;
    keepalive 32;
    }
    server {
    listen 80;
    server_name api.example.com;
    return 301 https://$server_name$request_uri;
    }
    server {
    listen 443 ssl http2;
    server_name api.example.com;
    ssl_certificate /etc/letsencrypt/live/api.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/api.example.com/privkey.pem;
    location / {
    proxy_pass http://hyperterse;
    proxy_http_version 1.1;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Connection "";
    }
    }
  2. Enable and start the service

    Terminal window
    sudo ln -s /etc/nginx/sites-available/my-query-gateway /etc/nginx/sites-enabled/
    sudo nginx -t && sudo systemctl reload nginx
  3. SSL with Let’s Encrypt

    Terminal window
    sudo apt install certbot python3-certbot-nginx
    sudo certbot --nginx -d api.example.com