Haste

Haste is an open-source pastebin software written in Node.js, which is easily installable in any network. It can be backed by either redis or filesystem, and has a very easy adapter interface for other stores. A publicly available version can be found at hastebin.com.


Note

For this guide you should be familiar with the basic concepts of

License

haste-server is released under the MIT License.

Prerequisites

We’re using Node.js version 20, but others should work too:

[isabell@stardust ~]$ uberspace tools version use node 20
Selected Node.js version 20
The new configuration is adapted immediately. Minor updates will be applied automatically.
[isabell@stardust ~]$

Setup your URL:

[isabell@stardust ~]$ uberspace web domain list
isabell.uber.space
[isabell@stardust ~]$

Installation

First clone the GitHub repository:

[isabell@stardust ~]$ git clone https://github.com/toptal/haste-server ~/haste
Cloning into '/home/isabell/haste'...
remote: Enumerating objects: 9, done.
remote: Counting objects: 100% (9/9), done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 2069 (delta 3), reused 0 (delta 0), pack-reused 2060
Receiving objects: 100% (2069/2069), 1.38 MiB | 2.98 MiB/s, done.
Resolving deltas: 100% (760/760), done.
[isabell@stardust ~]$

Then install the dependencies with npm install:

[isabell@stardust ~]$ cd haste/
[isabell@stardust haste]$ npm install
added 203 packages, and audited 204 packages in 13s
[isabell@stardust ~]$

Configuration

Storage

haste-server currently supports six storage solutions, of which File, Redis and Postgres are supported by Uberspace. The File backend is the most basic option and does not require additional software, Redis and Postgres do require additional steps. With Redis and Postgres you can set the expire option. This is off by default, but will constantly kick back expirations on each view or post.

Note

Pick only one.

File

To use file storage change the storage section in config.js to something like:

{
  "type": "file",
  "path": "./data"
}

where path represents where you want the files stored.

Redis

To use redis storage you must setup redis as specified here, then install the redis package in npm with npm install redis:

[isabell@stardust ~]$ npm install redis
[...]
+ redis@3.0.2
added 5 packages from 7 contributors and audited 6 packages in 3.141s
[isabell@stardust ~]$

Make sure to also change the port in ~/.redis/conf to something accessible, like 6379 and restart redis.

Once you’ve done that, your config section for storage should look like:

{
  "storage": {
    "type": "redis",
    "host": "localhost",
    "port": 6379,
    "db": 0
  },
}

If your Redis server is configured for password authentication, use the password field.

Postgres

To use postgres storage you must setup postgres as specified here, then install the pg package in npm with npm install pg:

[isabell@stardust ~]$ npm install pg
[...]
+ pg@8.0.3
added 17 packages from 9 contributors and audited 28 packages in 3.14s
[isabell@stardust ~]$

Once you’ve done that, create a new user for haste-server and set a password.

[isabell@stardust ~]$ createuser haste -P
Enter password for new role:
Enter it again:
[isabell@stardust ~]$

After that, create a database owned by the created user.

[isabell@stardust ~]$ createdb --encoding=UTF8 --owner=haste --template=template0 haste
[isabell@stardust ~]$

You will have to manually add a table to your postgres database:

[isabell@stardust ~]$ psql haste haste
Password for user haste:
psql (9.6.17)
Type "help" for help.

haste=> create table entries (id serial primary key, key varchar(255) not null, value text not null, expiration int, unique(key));
CREATE table
haste=> \q
[isabell@stardust ~]$

Once you’ve done that, your config section for storage should look like:

{
  "storage": {
    "type": "postgres",
    "connectionUrl": "postgres://haste:password@localhost:5432/haste"
  },
}

Replace password with the password of user haste.

For other configuration options, check the README file of haste-server.

Configure web server

Note

haste-server is running on port 7777 in the default configuration.

To make the application accessible from the outside, configure a web backend:

[isabell@stardust ~]$ uberspace web backend set / --http --port <port>
Set backend for / to port <port>; please make sure something is listening!
You can always check the status of your backend using "uberspace web backend list".
[isabell@stardust ~]$

Setup daemon

Create ~/etc/services.d/haste-server.ini with the following content:

[program:haste-server]
directory=%(ENV_HOME)s/haste/
command=npm start
autorestart=true
startsecs=30
stopasgroup=true

After creating the configuration, tell supervisord to refresh its configuration and start the service:

[isabell@stardust ~]$ supervisorctl reread
SERVICE: available
[isabell@stardust ~]$ supervisorctl update
SERVICE: added process group
[isabell@stardust ~]$ supervisorctl status
SERVICE                            RUNNING   pid 26020, uptime 0:03:14
[isabell@stardust ~]$

If it’s not in state RUNNING, check your configuration.

Updates

If there is a new version available, you can get the code using git:

[isabell@stardust ~]$ cd ~/haste
[isabell@stardust haste]$ git pull origin
From https://github.com/toptal/haste-server
Updating b8b2e4bc..96ac381a
[…]
[isabell@stardust ~]$

Then you need to restart the service daemon, so the new code is used by the webserver:

[isabell@stardust ~]$ supervisorctl restart haste-server
haste-server: stopped
haste-server: started
[isabell@stardust ~]$

It might take a few minutes before Haste server comes back online because npm re-checks and installs dependencies. You can check the service’s log file using supervisorctl tail -f haste-server.


Tested on Uberspace 7.15.6. with haste-server and

Written by: tobimori <tobias@moeritz.cc>