Compare commits

...

5 Commits

4 changed files with 32 additions and 13 deletions

View File

@ -23,7 +23,8 @@ docker-stop:
docker-test: docker-local docker-stop
docker run -p 4567:4567 --name chhoto-url -e password="${PASSWORD}" -e public_mode="${PUBLIC_MODE}" \
-e site_url="${SITE_URL}" -e db_url="${DB_URL}" -e redirect_method="${REDIRECT_METHOD}" \
-e slug_style="${SLUG_STYLE}" -e slug_length="${SLUG_LENGTH}" -d chhoto-url
-e slug_style="${SLUG_STYLE}" -e slug_length="${SLUG_LENGTH}" -e cache_control_header="${CACHE_CONTROL_HEADER}"\
-d chhoto-url
docker logs chhoto-url -f
docker-dev: build-dev

View File

@ -24,8 +24,8 @@ using the "feature request" template.
## But why another URL shortener?
Most URL shorteners are either bloated with unnecessary features, or are a pain to set up.
Even fewer are written with simplicity and lightness in mind. When I saw the simply-shorten
project (linked below), I really liked the idea but thought that it missed some details. Also,
Even fewer are written with simplicity and lightness in mind. When I saw the `simply-shorten`
project (linked below), I really liked the idea but thought that it missed some features. Also,
I didn't like the fact that a simple app like this had a ~200 MB docker image (mostly due to the
included java runtime). So, I decided to rewrite it in Rust and add some features to it that I
thought were essential (e.g. hit counting).
@ -133,6 +133,10 @@ the `slug_length` variable. It defaults to 8, and a minimum of 4 is supported.
To enable public mode, set `public_mode` to `Enable`. With this, anyone will be able to add
links. Listing existing links or deleting links will need admin access using the password.
By default, the server sends `no-cache` and `private` Cache-Control headers. To disable those,
set `cache_control_header` to `Disable`. It might help boost performance if served through a
proxy.
## Instructions for CLI usage
The application can be used from the terminal using something like `curl`. In all the examples
below, replace `http://localhost:4567` with where your instance of `chhoto-url` is accessible.

View File

@ -34,6 +34,11 @@ async fn main() -> Result<()> {
.parse::<u16>()
.expect("Supplied port is not an integer");
let cache_control_header = env::var("cache_control_header")
.ok()
.filter(|s| !s.trim().is_empty())
.unwrap_or(String::from("Enable"));
// Actually start the server
HttpServer::new(move || {
App::new()
@ -49,6 +54,11 @@ async fn main() -> Result<()> {
.app_data(web::Data::new(AppState {
db: database::open_db(db_location.clone()),
}))
.wrap(if cache_control_header == "Disable" {
middleware::DefaultHeaders::new()
} else {
middleware::DefaultHeaders::new().add(("Cache-Control", "no-cache, private"))
})
.service(services::link_handler)
.service(services::getall)
.service(services::siteurl)

View File

@ -9,32 +9,36 @@ services:
ports:
- 4567:4567
environment:
# Change if you want to mount the database somewhere else
# Change if you want to mount the database somewhere else.
# In this case, you can get rid of the db volume below
# and instead do a mount manually by specifying the location
# and instead do a mount manually by specifying the location.
# - db_url=/urls.sqlite
# Change it in case you want to set the website name
# displayed in front of the shorturls, defaults to
# the hostname you're accessing it from
# the hostname you're accessing it from.
# - site_url=https://www.example.com
- password=$3CuReP4S$W0rD
# Pass the redirect method, if needed TEMPORARY and PERMANENT
# are accepted values, defaults to PERMANENT
# Pass the redirect method, if needed. TEMPORARY and PERMANENT
# are accepted values, defaults to PERMANENT.
# - redirect_method=TEMPORARY
# By default, the auto-generated pairs are adjective-name pairs
# If you want UIDs, please change slug_style to UID
# Supported values for slug_style are Pair and UID
# The length is 8 by default, and a minimum of 4 is allowed
# By default, the auto-generated pairs are adjective-name pairs.
# If you want UIDs, please change slug_style to UID.
# Supported values for slug_style are Pair and UID.
# The length is 8 by default, and a minimum of 4 is allowed.
# - slug_style=Pair
# - slug_length=8
# In case you want to provide public access to adding links (and not
# delete, or listing), change the following option to Enable
# delete, or listing), change the following option to Enable.
# - public_mode=Disable
# By default, the server sends `no-cache` and `private` Cache-Control
# headers. To disable those, change the following option to Disable.
# - cache_control_header=Enable
volumes:
- db:/urls.sqlite
networks: