Skip to content

📚 The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.

Improve setup instructions, merge COOKIE_DOMAIN and FRONTEND_DOMAIN

Smaug6739b268552d8511
diff --git a/backend/main.go b/backend/main.go
index 05c93416..83cbc296 100644
--- a/backend/main.go
+++ b/backend/main.go
@@ -2,19 +2,27 @@ package main
import (
"alexandrie/server"
+ "alexandrie/utils"
"fmt"
"os"
+
+ "github.com/joho/godotenv"
)
func main() {
- server, application := server.SetupServer()
+
+ godotenv.Load() // Load .env file if present
+
+ utils.SetDomainEnv() // Set DOMAIN_CLIENT and DOMAIN_COOKIE from "FRONTEND_URL" if needed
port := os.Getenv("BACKEND_PORT")
if port == "" {
- fmt.Fprintln(os.Stderr, "Error: BACKEND_PORT environment variable not set")
+ fmt.Fprintln(os.Stderr, "⚠️ Error: BACKEND_PORT environment variable not set")
os.Exit(1)
}
+ server, application := server.SetupServer()
+
fmt.Println("Starting server on port:", port)
defer application.DB.Close()
- server.Run(":" + fmt.Sprintf("%s", port))
+ server.Run(":" + port)
}
diff --git a/backend/server/server.go b/backend/server/server.go
index fa0faf20..23c0b40f 100644
--- a/backend/server/server.go
+++ b/backend/server/server.go
@@ -10,11 +10,9 @@ import (
"github.com/BurntSushi/toml"
"github.com/gin-gonic/gin"
_ "github.com/go-sql-driver/mysql"
- "github.com/joho/godotenv"
)
func SetupServer() (*gin.Engine, *app.App) {
- godotenv.Load()
workingDir, err := os.Getwd()
if err != nil {
diff --git a/backend/utils/domains.go b/backend/utils/domains.go
new file mode 100644
index 00000000..b4a2f1d5
--- /dev/null
+++ b/backend/utils/domains.go
@@ -0,0 +1,43 @@
+package utils
+
+import (
+ "fmt"
+ "net/url"
+ "os"
+ "strings"
+)
+
+// SetDomainEnv initializes DOMAIN_CLIENT and COOKIE_DOMAIN environment variables
+// based on FRONTEND_URL (if defined).
+// If FRONTEND_URL is not set, the function does nothing.
+//
+// Example:
+// FRONTEND_URL=https://alexandrie-hub.fr
+// -> DOMAIN_CLIENT=https://alexandrie-hub.fr
+// -> COOKIE_DOMAIN=alexandrie-hub.fr
+//
+// FRONTEND_URL=http://localhost:8200
+// -> DOMAIN_CLIENT=http://localhost:8200
+// -> COOKIE_DOMAIN=localhost
+func SetDomainEnv() {
+ frontendURL := strings.TrimSpace(os.Getenv("FRONTEND_URL"))
+ if frontendURL == "" {
+ return
+ }
+
+ u, err := url.Parse(frontendURL)
+ if err != nil || u.Host == "" {
+ fmt.Fprintf(os.Stderr, "⚠️ Invalid FRONTEND_URL env variable: %s\n Expected format: http(s)://<host>[:port] \n > Example: https://alexandrie-hub.fr \n > Example: http://localhost:8200\n", frontendURL)
+ os.Exit(1)
+ }
+
+ // Remove port for cookie domain if present
+ host := u.Host
+ if idx := strings.Index(host, ":"); idx != -1 {
+ host = host[:idx]
+ }
+
+ // Set derived environment variables
+ _ = os.Setenv("DOMAIN_CLIENT", fmt.Sprintf("%s://%s", u.Scheme, u.Host))
+ _ = os.Setenv("COOKIE_DOMAIN", host)
+}
diff --git a/docker-compose.yml b/docker-compose.yml
index 9246d3bf..7b326ee2 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -5,9 +5,7 @@
# - Alexandrie Backend
# - Alexandrie Frontend
-# To use the local code (if you have cloned the repo, replace the backend/frontend image with a build context)
-## build:
-## context: ./backend
+# For details please refer to the documentation (./docs/setup.md)
services:
# MySQL Database
@@ -32,22 +30,21 @@ services:
retries: 5
start_period: 30s
- # Object Storage
+ # Object Storage (RustFS, S3 compatible)
rustfs:
image: rustfs/rustfs:latest
container_name: alexandrie-rustfs
restart: unless-stopped
environment:
- # définition des clés directement
RUSTFS_ACCESS_KEY: alexandrie-key
RUSTFS_SECRET_KEY: alexandrie-secret
- RUSTFS_CONSOLE_ENABLE: 'false' # ou true si tu veux console graphique
- # autres variables selon besoin (volume, domain, etc.)
+ RUSTFS_CONSOLE_ENABLE: 'false' # Disable web console
+ RUSTFS_LOG_LEVEL: info
ports:
- - '9000:9000' # API S3
+ - '9000:9000'
volumes:
- rustfs_data:/data
- - rustfs_data:/logs
+ - rustfs_logs:/logs
networks:
- alexandrie-network
healthcheck:
@@ -62,35 +59,35 @@ services:
image: ghcr.io/smaug6739/alexandrie-backend:latest
container_name: alexandrie-backend
environment:
+ # General configuration
+ BACKEND_PORT: 8201
+ GIN_MODE: release # Set to 'release' for production, 'debug' for development
+
# Database Configuration
DATABASE_HOST: mysql
DATABASE_PORT: 3306
DATABASE_NAME: alexandrie
DATABASE_USER: alexandrie
DATABASE_PASSWORD: password
- ALLOW_UNSECURE: 'true' # Set to 'true' if you run without HTTPS (e.g., local dev); in production, use 'false' and set up HTTPS
-
- # Application Configuration
- JWT_SECRET: your-secure-jwt-secret-key-change-this-in-production
- DOMAIN_CLIENT: http://localhost:8200 # For CORS Policy, if you have "Cors" error, check this
- COOKIE_DOMAIN: localhost # Very optional, can be left empty. For auth cookies: If you can't login (or you are disconnected immediatly), check this; DON'T set an URL just the DOMAIN (e.g., "example.com" or "localhost")
- # MinIO Configuration (optional, you can replace config with "" to disable MinIO usage)
+ # Object storage configuration (S3 compatible like RustFS, MinIO, etc.)
+ # OPTIONAL: If you don't want to use the CDN feature you can leave these variables empty
MINIO_ENDPOINT: rustfs:9000
MINIO_ACCESSKEY: alexandrie-key
MINIO_SECRETKEY: alexandrie-secret
MINIO_BUCKET: alexandrie
- # SMTP Configuration (optional)
+ # SMTP Configuration (only for password reset emails)
+ # OPTIONAL: If you don't want to use email features, you can leave these variables empty
SMTP_HOST: ''
SMTP_MAIL: ''
SMTP_PASSWORD: ''
- # Port Configuration
- BACKEND_PORT: 8201
- CPWD: /app/
- CONFIG_CPWD: ''
- GIN_MODE: release
+ # Application authentication and security
+ JWT_SECRET: your-secure-jwt-secret-key-change-this-in-production # Change this secret in production!
+ FRONTEND_URL: http://localhost:8200 # URL where the frontend is hosted
+ ALLOW_UNSECURE: 'true' # Set to 'true' if you run without HTTPS (e.g., local dev);
+
ports:
- '8201:8201'
depends_on:
@@ -128,3 +125,5 @@ volumes:
driver: local
rustfs_data:
driver: local
+ rustfs_logs:
+ driver: local