1
0
Fork 0
mirror of https://github.com/SunRed/haste-server.git synced 2025-09-05 21:10:16 +02:00

Added proper documentation

This commit is contained in:
zneix 2020-08-29 05:29:39 +02:00
parent 1efc62a8c5
commit b4f42219e5
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: 911916E0523B22F6
9 changed files with 326 additions and 311 deletions

46
docs/generators.md Normal file
View file

@ -0,0 +1,46 @@
# Generators
Here's a list of all supported random string generators.
One of these is meant to be set in `config.json` as `keyGenerator` object.
Default type is [random](#random) with all alphanumeric characters as keyspace.
**Table of Contents**
- [Phonetic](#phonetic)
- [Random](#random)
- [Dictionary](#dictionary)
## Random
Generates a random key from set of characters in `keysapce`.
Keyspace can be left empty to use all alphanumeric characters instead.
``` json
{
"type": "random",
"keyspace": "abcdef"
}
```
## Phonetic
Generates phonetic key with a combination of vovels similar to `pwgen` command on linux.
``` json
{
"type": "phonetic"
}
```
## Dictionary
Generates a key consisting of words from file named `words.txt`, one word per line.
To avoid any issues with URL length, it is recommended to use `keyLength` 5 or shorter.
```json
{
"type": "dictionary",
"path": "./words.txt"
}
```

118
docs/install.md Normal file
View file

@ -0,0 +1,118 @@
# Short instructions
1. Install [node](https://nodejs.org/en/) and npm packages.
2. Rename `example.config.js` to `config.js`. (Defaults are enough)
3. (Optional) Change document storage system ([guide](./storage.md))
4. Run with `npm start` or `node .`
# Full installation instructions
> **NOTE:** This guide assumes you're on a Linux server, like Debian 10 or Ubuntu 20.04.
If you're using windows, you will have to improvise a bit with Autorestarts.
**Table of Contents**
- [Set up node](#set-up-node)
- [Install dependencies](#install-dependencies)
- [Edit configuration](#edit-configuration)
- [Run the server](#run-the-server)
- [Further steps](#further-steps)
## Set up node
Hastebin server runs on the JavaScript runtime called node, so you need to download it first:
```bash
curl -sL https://deb.nodesource.com/setup_14.x | bash -
apt-get install -y nodejs
```
If method above didn't work [use this guide](https://github.com/nodesource/distributions/blob/master/README.md#installation-instructions).
For Windows enviroments, you can [download and install node from its website](https://nodejs.org/en/download/current/).
Node should also automatically install [npm](https://docs.npmjs.com/about-npm/) which will help us install dependencies. You can verify your installations, with following commands
```bash
node -v
npm -v
```
## Install dependencies
Hastebin makes use of several node packages, which can be installed with npm by executing this command:
```bash
npm install
```
## Edit configuration
There is an [example configuration file](../example.config.json) available for you to copy:
```bash
cp example.config.json config.json
```
By default storage system stores haste documents as hashed files in `./data` directory.
Rest of provided defaults are enough to run the server, however, example config contains comments about what each value does and you can adjust the options to your likings.
[Guide for all supported storage systems.](./storage.md).
[Guide for all supported key generators.](./generators.md).
## Run the server
You should now be able to start the server with the following command:
```bash
npm run-script start
```
To stop server the server, hit `Ctrl + C`
## Further steps
Once you're good to go and server is running you probably want to keep it alive 24/7 - to achieve that you can choose from variety of things like: pm2, systemd, screen, etc.
Here, I will cover a basic guide to the PM2 - a program which will make sure your server is running 24/7 with autorestarts.
Download it with npm:
```bash
sudo npm install pm2 -g
```
Now assign Hastebin server to pm2's daemon:
```bash
pm2 start "npm start" --name=haste
```
To ensure haste server will automatically start after server reboot you need to retrieve startup script and execute it.
Example:
```bash
$ pm2 startup
[PM2] Init System found: systemd
[PM2] To setup the Startup Script, copy/paste the following command:
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u zneix --hp /home/zneix
```
Now, just copy-paste the last line into your terminal and you should be done.
PM2 Commands:
- `pm2 list`: displays list of all pm2 processes
- `pm2 logs haste`: displays server logs
- `pm2 restart haste`: restarts Hastebin server (you will need to do that after config changes, etc.)
- `pm2 stop haste`: stops Hastebin server
- `pm2 start haste`: starts Hastebin server if it was stopped manually before

100
docs/storage.md Normal file
View file

@ -0,0 +1,100 @@
# Storage
Here's a list of all supported document store systems.
One of these is meant to be set in `config.json` as `storage` object.
Default type is [file](#file) with save directory at `./data`.
With some storage options you can set up document expiration - after which documents will no longer be available
**Table of Contents**
In alphabetical order:
- [Amazon S3](#amazon-s3)
- [File](#file)
- [Memcached](#memcached)
- [MongoDB](#mongodb)
- [Postgres](#postgres)
- [Redis](#redis)
- [RethinkDB](#rethinkdb)
## Amazon S3
Not rewritten yet, to be filled in
## File
Default storage option, with no further installation required.
Stores documents in a specified directory in files named with a md5 hash of the key to avoid any security issues.
Default path is `./data`
> **NOTE:** File storage option does not support document expiration!
Config:
```json
{
"type": "file",
"path": "./data"
}
```
## Memcached
Not rewritten yet, to be filled in
## MongoDB
Requires npm package (Tested on v3.6.0):
```bash
npm i mongodb@3.6.0
```
Stores documents in a specified database in a collection named `entries`.
Expiration property in config can be changed to a value in seconds after which entries will not be served to users.
Optimal default config:
> **NOTE:** Depending on how your MongoDB server is configured, options as connectionUri may vary.
If server has no authentication, you can omit the `auth` object.
Check [documentation](http://mongodb.github.io/node-mongodb-native/3.5/api/MongoClient.html) for more detailed explanation about available `clientOptions` properties.
```json
{
"type": "mongodb",
"expire": 0,
"connectionUri": "mongodb://localhost:27017/haste",
"clientOptions": {
"useUnifiedTopology": true,
"useNewUrlParser": true,
"keepAlive": true,
"keepAliveInitialDelay": 60000,
"poolSize": 30,
"socketTimeoutMS": 360000,
"connectTimeoutMS": 360000,
"auth": {
"user": "username",
"password": "password"
},
"authSource": "admin"
}
}
```
## Postgres
Not rewritten yet, to be filled in
## Redis
Not rewritten yet, to be filled in
## RethinkDB
Not rewritten yet, to be filled in