CI / go (Server) (push) Successful in 23m34s
CI / go (Web-App) (push) Successful in 12m21s
CI / frontend (push) Failing after 10m55s
Docs / build (push) Canceled after 0s
Docs / deploy (push) Canceled after 0s
CI / desktop (ubuntu-latest) (push) Successful in 1h57m19s
CI / mobile (push) Failing after 5m8s
CI / docker (push) Failing after 41m19s
CI / desktop (macos-latest) (push) Canceled after 0s
CI / desktop (windows-latest) (push) Canceled after 0s
docwell-db's base image (tajniak81/pocketbase-docker-root) listens on 8070 by default. Use that port everywhere instead of overriding it to 8090: the Database image, every Docker compose file and .env example, the AIO start script, docwell-server's DOCWELL_PB_URL default, and the docs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
116 lines
3.5 KiB
Go
116 lines
3.5 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
// Package config loads docwell-server settings from environment variables.
|
|
package config
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
type Config struct {
|
|
// Addr is the listen address of the public API, e.g. ":8080".
|
|
Addr string
|
|
// PublicURL is the externally reachable base URL of the server.
|
|
PublicURL string
|
|
// WebURL is the base URL of docwell-web; links in emails open it.
|
|
WebURL string
|
|
// CORSOrigins lists origins allowed to call the API from a browser.
|
|
CORSOrigins []string
|
|
|
|
// SignupEnabled allows self-service signup (the first account always can).
|
|
SignupEnabled bool
|
|
// SignupDomains limits signup to these email domains when not empty.
|
|
SignupDomains []string
|
|
|
|
PocketBaseURL string
|
|
PocketBaseEmail string
|
|
PocketBasePassword string
|
|
|
|
// DataDir holds docwell-server's own files (the search index).
|
|
DataDir string
|
|
// MaxUploadMB caps one attachment.
|
|
MaxUploadMB int
|
|
|
|
ShutdownTimeout time.Duration
|
|
|
|
// AuditRetentionDays is how long audit log entries are kept (0 = forever).
|
|
AuditRetentionDays int
|
|
// WebhooksAllowLocal lets webhooks call loopback and link-local
|
|
// addresses (for development; off in production).
|
|
WebhooksAllowLocal bool
|
|
}
|
|
|
|
// Load reads the configuration from the environment and validates it.
|
|
func Load() (Config, error) {
|
|
return fromLookup(os.LookupEnv)
|
|
}
|
|
|
|
func fromLookup(lookup func(string) (string, bool)) (Config, error) {
|
|
get := func(key, def string) string {
|
|
if v, ok := lookup(key); ok && v != "" {
|
|
return v
|
|
}
|
|
return def
|
|
}
|
|
|
|
cfg := Config{
|
|
Addr: get("DOCWELL_ADDR", ":8080"),
|
|
PublicURL: strings.TrimRight(get("DOCWELL_PUBLIC_URL", "http://localhost:8080"), "/"),
|
|
WebURL: strings.TrimRight(get("DOCWELL_WEB_URL", "http://localhost:3000"), "/"),
|
|
CORSOrigins: splitList(get("DOCWELL_CORS_ORIGINS", "http://localhost:5173,http://localhost:3000")),
|
|
PocketBaseURL: strings.TrimRight(get("DOCWELL_PB_URL", "http://127.0.0.1:8070"), "/"),
|
|
PocketBaseEmail: get("DOCWELL_PB_EMAIL", ""),
|
|
PocketBasePassword: get("DOCWELL_PB_PASSWORD", ""),
|
|
SignupEnabled: get("DOCWELL_SIGNUP_ENABLED", "true") == "true",
|
|
SignupDomains: splitList(get("DOCWELL_SIGNUP_DOMAINS", "")),
|
|
DataDir: get("DOCWELL_DATA_DIR", "./data"),
|
|
ShutdownTimeout: 15 * time.Second,
|
|
WebhooksAllowLocal: get("DOCWELL_WEBHOOKS_ALLOW_LOCAL", "false") == "true",
|
|
}
|
|
|
|
cfg.AuditRetentionDays = 365
|
|
if v := get("DOCWELL_AUDIT_RETENTION_DAYS", ""); v != "" {
|
|
n, err := strconv.Atoi(v)
|
|
if err != nil || n < 0 {
|
|
return Config{}, errors.New("DOCWELL_AUDIT_RETENTION_DAYS must be 0 (keep forever) or more")
|
|
}
|
|
cfg.AuditRetentionDays = n
|
|
}
|
|
|
|
if v := get("DOCWELL_SHUTDOWN_TIMEOUT", ""); v != "" {
|
|
d, err := time.ParseDuration(v)
|
|
if err != nil {
|
|
return Config{}, errors.New("DOCWELL_SHUTDOWN_TIMEOUT: " + err.Error())
|
|
}
|
|
cfg.ShutdownTimeout = d
|
|
}
|
|
|
|
cfg.MaxUploadMB = 50
|
|
if v := get("DOCWELL_MAX_UPLOAD_MB", ""); v != "" {
|
|
n, err := strconv.Atoi(v)
|
|
if err != nil || n < 1 || n > 100 {
|
|
return Config{}, errors.New("DOCWELL_MAX_UPLOAD_MB must be between 1 and 100")
|
|
}
|
|
cfg.MaxUploadMB = n
|
|
}
|
|
|
|
if cfg.PocketBaseEmail == "" || cfg.PocketBasePassword == "" {
|
|
return Config{}, errors.New("DOCWELL_PB_EMAIL and DOCWELL_PB_PASSWORD are required")
|
|
}
|
|
return cfg, nil
|
|
}
|
|
|
|
func splitList(s string) []string {
|
|
var out []string
|
|
for _, part := range strings.Split(s, ",") {
|
|
if part = strings.TrimSpace(part); part != "" {
|
|
out = append(out, part)
|
|
}
|
|
}
|
|
return out
|
|
}
|