Rocket Powered Pastebin (rktpb
| paste.rs
)
A pastebin that does just enough to be really useful.
- Really fast, really lightweight.
- Renders markdown like GitHub.
- Highlights
source code
. - Returns plain text, too.
- Has a simple API usable via CLI.
- Has support for CORS.
- Limits paste upload sizes.
- No database: uses the file system.
- Automatically deletes stale pastes.
This pastebin powers paste.rs
, a public instance. Further usage details can
be found there.
Rocket Powered Pastebin (rktpb
) is written in
Rust with Rocket. To start the
server, use cargo
:
# clone the repository
git clone https://github.com/SergioBenitez/rktpb
# change into directory: the `static` folder needs to be in CWD before running
cd rktpb
# compile and start the server with the default config
cargo run
Configuration is provided via environment variables or a TOML file. A set of defaults is always provided.
The complete list of configurable parameters is below:
Name | Default Value | Description |
---|---|---|
id_length |
3 |
paste ID length |
upload_dir |
"upload" |
directory to save uploads in |
paste_limit |
"384KiB" |
maximum paste upload file size |
max_age |
"30 days" |
how long a paste is considered fresh |
reap_interval |
"5 minutes" |
how often to reap stale uploads |
server_url |
"http://{address}:{port}" |
URL server is reachable at |
cors.{host} |
["{HTTP method}"..] |
allow CORS {HTTP methods} for {host} |
address |
"127.0.0.1" |
address to listen on |
port |
8000 |
port to listen on |
keep_alive |
5 |
HTTP keep-alive in seconds |
ident |
"Rocket" |
server Ident header |
ip_header |
"X-Real-IP" |
header to inspect for client IP |
log_level |
"normal" |
console log level |
cli_colors |
true |
enable (detect TTY) or disable CLI colors |
shutdown.ctrlc |
true |
whether <ctrl-c> initiates a shutdown |
shutdown.signals |
["term", "hup"] |
signals that initiate a shutdown |
shutdown.grace |
5 |
grace period length in seconds |
shutdown.mercy |
5 |
mercy period length in seconds |
You'll definitely want to configure the values in the first two categories, from
id_length
to cors
.
You should likely use the defaults for the rest.
Use an environment variable name equivalent to the parameter name prefixed with
PASTE_
:
PASTE_ID_LENGTH=10 PASTE_MAX_AGE="1 year" ./rktpb
To set structured data via environment variables, such as CORS, use TOML-like syntax:
PASTE_CORS='{"http://example.com"=["get", "post"]}' ./rktpb
See Paste.toml.template
for a template with all of the
defaults set as well as a dummy cors
configuration for http://example.com
that allows the options
, get
, post
, and delete
HTTP methods.
mv Paste.toml.template Paste.toml
By default, the application searches for a file called Paste.toml
in the CWD.
The path to the file can be overridden by setting PASTE_CONFIG
. For example,
to use a file named rktpb.toml
, use PASTE_CONFIG="rktpb.toml" ./rktpb
.
To deploy, build in release mode and ship/run the resulting binary along with
static/
, templates/
, and any config:
# build in release mode for `${TARGET}`
cargo build --release --target ${TARGET}
# create a tarball of everything that's needed
tar -cvzf "rktpb.tar.gz" \
Paste.toml static templates \
-C target/${TARGET}/release rktpb
However you choose to deploy, you'll need to ensure that the CWD at the time the
server is started contains the static
and templates
directories as well as
the config file, if one is used.
Note that when the server is compiled in release
mode, the [release]
section
of a TOML config file can be used to override config values; the same is true
when compiled in debug
mode with [debug]
.
Rocket Powered Pastebin (rktpb
| paste.rs
)
Copyright © 2020 Sergio Benitez
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3 (GNU AGPLv3) as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU AGPLv3 LICENSE for more details.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project shall be licensed under the GNU AGPLv3 License, without any additional terms or conditions.