~sfr/artemis

d155ebf8593a53b140dbc7b70690f79f99932e5f — Sol Fisher Romanoff 8 months ago 87f4aab
Add support for custom userdir path, set defaults
3 files changed, 18 insertions(+), 7 deletions(-)

M README.md
M config.toml
M main.go
M README.md => README.md +9 -4
@@ 8,17 8,22 @@ $ go build
$ ./artemis
```

## configuration

artemis checks for a `config.toml` file in the following locations, in order:
* `.`
* `$XDG_CONFIG_HOME/artemis`
* `$HOME/.config/artemis`
* `/etc/artemis`

in the config, you must specify the path to a TLS keypair, and the
root directory to serve files from.
in the config, you must specify the location of a TLS cert and key.

you may optionally change the port artemis will listen on. by default,
artemis listens on port 1965, the default gemini port.

you may optionally set a port that artemis will listen on. if unset,
artemis will listen on port 1965, the default gemini port.
you may optionally provide custom paths for the index or user
directories. by default, the index points to `/var/gemini` and the
userdir is `$HOME/public_gemini`.

## contributing


M config.toml => config.toml +3 -1
@@ 1,4 1,6 @@
tlsCert  = "fullchain.pem"
tlsKey   = "privkey.pem"
indexDir = "/var/gemini"
port     = 1965

indexDir = "/var/gemini"
userDir  = "public_gemini"

M main.go => main.go +6 -2
@@ 18,14 18,17 @@ import (
type Config struct {
	TLSCert  string
	TLSKey   string
	IndexDir string
	Port     int
	IndexDir string
	UserDir  string
}

var config Config

func main() {
	viper.SetDefault("port", 1965)
	viper.SetDefault("indexDir", "/var/gemini")
	viper.SetDefault("userDir", "public_gemini")

	// read config.toml
	log.Println("reading config file")


@@ 100,7 103,8 @@ func route(conn io.ReadWriteCloser) {
	var path string
	re := regexp.MustCompile(`^/~([A-Za-z0-9]+)(/.*)?/?$`)
	if re.MatchString(address.Path) {
		path = string(re.ReplaceAll([]byte(address.Path), []byte("/home/$1/public_gemini$2")))
		path = string(re.ReplaceAll([]byte(address.Path),
			[]byte("/home/$1/"+config.UserDir+"$2")))
	} else {
		path = config.IndexDir + address.Path