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.

Fixes with env variables

Smaug6739db55906667e1
diff --git a/.env.example b/.env.example
index a9d248c1..80d10d45 100644
--- a/.env.example
+++ b/.env.example
@@ -15,7 +15,7 @@
# If using a Reverse Proxy (Nginx/Traefik), use your public domain names here.
FRONTEND_URL=http://localhost:8200
API_URL=http://localhost:8201
-CDN_URL=http://localhost:9000/alexandrie
+CDN_URL=http://localhost:9000
# Flags to enable or disable certain app features
CONFIG_DISABLE_LANDING=false # Disable the landing page if set to true
@@ -34,8 +34,6 @@ MYSQL_PASSWORD=password
# ------------------------------------------------------------------------------
# 2. OBJECT STORAGE (RustFS / S3 Compatible)
RUSTFS_EXTERNAL_PORT=9005 # The port exposed on your host machine for S3 API access
-
-MINIO_ENDPOINT=localhost:9005 # The endpoint URL for the object storage (e.g., localhost:9000) Important to use the correct domain for signing URLs
MINIO_SECURE=false # Set to 'true' if your S3 endpoint uses HTTPS (true/false)
# Access credentials for the object storage
@@ -49,7 +47,6 @@ RUSTFS_LOG_LEVEL=info # Logging level (debug, info, warn, error)
# ------------------------------------------------------------------------------
# 3. BACKEND API CONFIGURATION
BACKEND_EXTERNAL_PORT=8201 # The port exposed on your host machine for the Backend API
-GIN_MODE=release # Application mode: 'debug' for development, 'release' for production
# Security: Secret key used to sign JWT tokens.
# /!\ IMPORTANT: Change this to a random long string in production /!\
diff --git a/.github/workflows/deploy_to_prod.yml b/.github/workflows/deploy_to_prod.yml
index 5390ce7e..a0ab5af4 100755
--- a/.github/workflows/deploy_to_prod.yml
+++ b/.github/workflows/deploy_to_prod.yml
@@ -63,8 +63,6 @@ jobs:
NODE_ENV=production
GIN_MODE=release
BACKEND_PORT=8201
- DOMAIN_CLIENT=https://alexandrie-hub.fr
- COOKIE_DOMAIN=alexandrie-hub.fr
DATABASE_USER=${{ secrets.DATABASE_USER }}
DATABASE_PASSWORD="${{ secrets.DATABASE_PASSWORD }}"
JWT_SECRET=${{ secrets.JWT_SECRET }}
diff --git a/backend/.env.example b/backend/.env.example
index 57af0a29..c85f2162 100644
--- a/backend/.env.example
+++ b/backend/.env.example
@@ -2,7 +2,7 @@ JWT_SECRET=your_secret_key
DATABASE_USER=root
DATABASE_PASSWORD=root
-DOMAIN_CLIENT=http://localhost:3000
+FRONTEND_URL=http://localhost:3000
COOKIE_DOMAIN=localhost
diff --git a/backend/app/app.go b/backend/app/app.go
index 654d748a..b0c9ee02 100644
--- a/backend/app/app.go
+++ b/backend/app/app.go
@@ -33,19 +33,20 @@ type Config struct {
}
type App struct {
- DB *sql.DB
- Snowflake *snowflake.Snowflake
- Config Config
- MinioClient *minio.Client
- MailClient *mail.Client
- Services *services.ServiceManager
- Repos *repositories.RepositoryManager
+ DB *sql.DB
+ Snowflake *snowflake.Snowflake
+ Config Config
+ MinioClient *minio.Client
+ SignerClient *minio.Client
+ MailClient *mail.Client
+ Services *services.ServiceManager
+ Repos *repositories.RepositoryManager
}
func InitApp(config Config) *App {
var app App
app.DB = DBConnection(config, false)
- app.MinioClient, _ = MinioConnection()
+ app.MinioClient, app.SignerClient, _ = MinioConnection()
app.MailClient = GetMailClient()
app.Snowflake = snowflake.NewSnowflake(1609459200000)
app.Config = config
diff --git a/backend/app/minio.go b/backend/app/minio.go
index ca787eb8..77e49b29 100644
--- a/backend/app/minio.go
+++ b/backend/app/minio.go
@@ -5,41 +5,61 @@ import (
"alexandrie/utils"
"context"
"fmt"
- "log"
+ "net/url"
"os"
+ "strings"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
"github.com/minio/minio-go/v7/pkg/lifecycle"
)
-func MinioConnection() (*minio.Client, error) {
+func MinioConnection() (*minio.Client, *minio.Client, error) {
ctx := context.Background()
- endpoint := os.Getenv("MINIO_ENDPOINT")
+
+ internalEndpoint := os.Getenv("MINIO_ENDPOINT")
+ publicEndpoint := os.Getenv("MINIO_PUBLIC_URL")
+
accessKeyID := os.Getenv("MINIO_ACCESSKEY")
secretAccessKey := os.Getenv("MINIO_SECRETKEY")
- if endpoint == "" || accessKeyID == "" || secretAccessKey == "" {
- return nil, fmt.Errorf("MINIO NOT CONFIGURED")
- }
- isSecure := os.Getenv("MINIO_SECURE") == "true"
- // Override: if MINIO_SECURE is not set, infer from endpoint
- if os.Getenv("MINIO_SECURE") == "" {
+ if internalEndpoint == "" || accessKeyID == "" || secretAccessKey == "" {
+ return nil, nil, fmt.Errorf("MINIO NOT CONFIGURED")
+ }
- isSecure = true
- // If localhost is used (start with localhost), disable SSL
- if len(endpoint) >= 9 && endpoint[:9] == "localhost" {
- isSecure = false
- }
+ // HTTPS detection
+ isSecure := true
+ if os.Getenv("MINIO_SECURE") != "" && os.Getenv("MINIO_SECURE") != "true" {
+ isSecure = false
+ } else if strings.HasPrefix(internalEndpoint, "localhost") || strings.HasPrefix(internalEndpoint, "127.") {
+ isSecure = false
}
// Initialize minio client object.
- minioClient, errInit := minio.New(endpoint, &minio.Options{
+ minioClient, errInit := minio.New(internalEndpoint, &minio.Options{
Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
Secure: isSecure,
})
if errInit != nil {
- log.Fatalln(errInit)
+ logger.Error(fmt.Sprintf("Failed to initialize MinIO client: %v", errInit))
+ os.Exit(1)
+ }
+
+ // Signer client for public URLs
+ publicURL, err := url.Parse(publicEndpoint)
+ if err != nil {
+ logger.Error("CONFIG: MINIO_PUBLIC_URL is not a valid URL")
+ os.Exit(1)
+ }
+ isPublicSecure := publicURL.Scheme == "https"
+ signerClient, err := minio.New(publicURL.Host, &minio.Options{
+ Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
+ Secure: isPublicSecure,
+ BucketLookup: minio.BucketLookupPath,
+ })
+ if err != nil {
+ logger.Error(fmt.Sprintf("Failed to create signer client: %v", err))
+ os.Exit(1)
}
// Setup main public bucket for user files (avatars, uploads, etc.)
@@ -50,7 +70,7 @@ func MinioConnection() (*minio.Client, error) {
backupBucket := utils.GetBackupBucketName()
setupPrivateBackupBucket(ctx, minioClient, backupBucket)
- return minioClient, errInit
+ return minioClient, signerClient, errInit
}
// setupPublicBucket creates and configures the main public bucket
@@ -61,7 +81,8 @@ func setupPublicBucket(ctx context.Context, minioClient *minio.Client, bucketNam
if errBucketExists == nil && exists {
logger.Info(fmt.Sprintf("We already own %s", bucketName))
} else {
- log.Fatalln(err)
+ logger.Error(fmt.Sprintf("Failed to create bucket %s: %v", bucketName, err))
+ os.Exit(1)
}
} else {
logger.Success("Successfully created " + bucketName)
@@ -82,7 +103,8 @@ func setupPublicBucket(ctx context.Context, minioClient *minio.Client, bucketNam
err = minioClient.SetBucketPolicy(ctx, bucketName, policy)
if err != nil {
- log.Fatalf("Failed to set bucket policy: %v", err)
+ logger.Error(fmt.Sprintf("Failed to set bucket policy: %v", err))
+ os.Exit(1)
}
logger.Success("Successfully set public bucket policy for " + bucketName)
}
@@ -95,7 +117,8 @@ func setupPrivateBackupBucket(ctx context.Context, minioClient *minio.Client, bu
if errBucketExists == nil && exists {
logger.Info(fmt.Sprintf("We already own %s", bucketName))
} else {
- log.Fatalln(err)
+ logger.Error(fmt.Sprintf("Failed to create private backup bucket %s: %v", bucketName, err))
+ os.Exit(1)
}
} else {
logger.Success("Successfully created private backup bucket: " + bucketName)
diff --git a/backend/controllers/backup.controller.go b/backend/controllers/backup.controller.go
index 39f63beb..6c719a36 100644
--- a/backend/controllers/backup.controller.go
+++ b/backend/controllers/backup.controller.go
@@ -58,7 +58,7 @@ func (ctr *Controller) CreateBackup(c *gin.Context) (int, any) {
}
// Start async backup
- jobId, err := ctr.app.Services.Backup.CreateBackupAsync(userId, options, ctr.app.MinioClient)
+ jobId, err := ctr.app.Services.Backup.CreateBackupAsync(userId, options, ctr.app.MinioClient, ctr.app.SignerClient)
if err != nil {
return http.StatusInternalServerError, err
}
diff --git a/backend/router/router.go b/backend/router/router.go
index 8d3526fe..e7efbba1 100644
--- a/backend/router/router.go
+++ b/backend/router/router.go
@@ -27,7 +27,7 @@ func InitRouter(app *app.App) *gin.Engine {
router.Use(cors.New(cors.Config{
AllowOriginFunc: func(origin string) bool {
// Main domain from environment variable
- domain := os.Getenv("DOMAIN_CLIENT")
+ domain := os.Getenv("FRONTEND_URL")
if origin == domain {
return true
diff --git a/backend/services/auth.service.go b/backend/services/auth.service.go
index 453a04e8..af7e1bb8 100644
--- a/backend/services/auth.service.go
+++ b/backend/services/auth.service.go
@@ -151,7 +151,7 @@ func (s *authService) RequestPasswordReset(username string, mailClient *mail.Cli
message.FromFormat("Alexandrie Team", os.Getenv("SMTP_MAIL"))
message.To(user.Email)
message.Subject("Alexandrie: Password Reset")
- message.SetBodyString(mail.TypeTextPlain, fmt.Sprintf("Your password reset link is: %s", os.Getenv("DOMAIN_CLIENT")+"/login/reset?token="+resetToken))
+ message.SetBodyString(mail.TypeTextPlain, fmt.Sprintf("Your password reset link is: %s", os.Getenv("FRONTEND_URL")+"/login/reset?token="+resetToken))
if err := mailClient.DialAndSend(message); err != nil {
return nil // Don't reveal errors
diff --git a/backend/services/backup.service.go b/backend/services/backup.service.go
index 5ee6b470..faeb8e9d 100644
--- a/backend/services/backup.service.go
+++ b/backend/services/backup.service.go
@@ -30,7 +30,7 @@ const (
// BackupService handles backup creation and management
type BackupService interface {
// CreateBackupAsync starts an async backup job and returns the job ID
- CreateBackupAsync(userId types.Snowflake, options types.BackupOptions, minioClient *minio.Client) (string, error)
+ CreateBackupAsync(userId types.Snowflake, options types.BackupOptions, minioClient *minio.Client, signerClient *minio.Client) (string, error)
// GetBackupStatus returns the current status of a backup job
GetBackupStatus(userId types.Snowflake, jobId string) (*types.BackupJob, error)
// CancelBackup cancels an ongoing backup job
@@ -58,7 +58,7 @@ func NewBackupService(nodeRepo repositories.NodeRepository) BackupService {
}
// CreateBackupAsync starts an asynchronous backup job
-func (s *backupService) CreateBackupAsync(userId types.Snowflake, options types.BackupOptions, minioClient *minio.Client) (string, error) {
+func (s *backupService) CreateBackupAsync(userId types.Snowflake, options types.BackupOptions, minioClient *minio.Client, signerClient *minio.Client) (string, error) {
if minioClient == nil {
return "", errors.New("minio client not initialized")
}
@@ -94,7 +94,7 @@ func (s *backupService) CreateBackupAsync(userId types.Snowflake, options types.
s.jobMutex.Unlock()
// Start async processing
- go s.processBackup(ctx, job, minioClient)
+ go s.processBackup(ctx, job, minioClient, signerClient)
return jobId, nil
}
@@ -205,7 +205,7 @@ func (s *backupService) CleanupExpiredBackups(minioClient *minio.Client) error {
}
// processBackup is the main backup processing goroutine
-func (s *backupService) processBackup(ctx context.Context, job *types.BackupJob, minioClient *minio.Client) {
+func (s *backupService) processBackup(ctx context.Context, job *types.BackupJob, minioClient *minio.Client, signerClient *minio.Client) {
defer func() {
if r := recover(); r != nil {
s.updateJobStatus(job, types.BackupStatusFailed, 0, "", fmt.Sprintf("Backup failed: %v", r))
@@ -374,13 +374,15 @@ func (s *backupService) processBackup(ctx context.Context, job *types.BackupJob,
`attachment; filename="alexandrie-backup-`+time.Now().Format("2006-01-02 15:04:05")+`.zip"`,
)
- presignedURL, err := minioClient.PresignedGetObject(
+ // Sign the URL using the public endpoint
+ presignedURL, err := signerClient.PresignedGetObject(
context.Background(),
backupBucket,
objectName,
time.Duration(backupExpiryHours)*time.Hour,
reqParams,
)
+
if err != nil {
s.updateJobStatus(job, types.BackupStatusFailed, 0, "", fmt.Sprintf("Failed to generate download URL: %v", err))
return
diff --git a/docker-compose.yml b/docker-compose.yml
index 2dfe0576..a592a309 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -47,15 +47,15 @@ services:
# Alexandrie Backend
backend:
- image: ghcr.io/smaug6739/alexandrie-backend:latest
+ build: ./backend
container_name: alexandrie-backend
environment:
# General configuration
BACKEND_PORT: 8201
- GIN_MODE: ${GIN_MODE:-release}
+ GIN_MODE: release
JWT_SECRET: ${JWT_SECRET:-your-secure-jwt-secret-key-change-this-in-production}
COOKIE_DOMAIN: ${COOKIE_DOMAIN:-localhost:8200} # Common domain for cookies (e.g., yourdomain.com if you have frontend.yourdomain.com and api.yourdomain.com)
- DOMAIN_CLIENT: ${FRONTEND_URL:-http://localhost:8200} # URL where the frontend is hosted (for CORS policy and url generation in emails)
+ FRONTEND_URL: ${FRONTEND_URL:-http://localhost:8200} # URL where the frontend is hosted (for CORS policy and url generation in emails)
ALLOW_UNSECURE: '${ALLOW_UNSECURE:-true}' # Set to 'true' if you run without HTTPS (e.g., local dev);
# Flags
@@ -70,7 +70,8 @@ services:
# 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: ${MINIO_ENDPOINT:-rustfs:9000}
+ MINIO_ENDPOINT: rustfs:9000
+ MINIO_PUBLIC_URL: ${CDN_URL:-http://localhost:${RUSTFS_EXTERNAL_PORT:-9000}}
MINIO_SECURE: '${MINIO_SECURE:-false}' # Set to 'true' if your S3 endpoint uses HTTPS
MINIO_ACCESSKEY: ${RUSTFS_ACCESS_KEY:-alexandrie-key}
MINIO_SECRETKEY: ${RUSTFS_SECRET_KEY:-alexandrie-secret}
@@ -84,6 +85,8 @@ services:
ports:
- '${BACKEND_EXTERNAL_PORT:-8201}:8201'
+ extra_hosts:
+ - 'localhost:host-gateway'
depends_on:
mysql:
condition: service_healthy
@@ -106,7 +109,7 @@ services:
# Runtime configuration - builds with these values at startup
NUXT_PUBLIC_BASE_API: ${API_URL:-http://localhost:8201}
- NUXT_PUBLIC_BASE_CDN: ${CDN_URL:-http://localhost:9000/alexandrie}
+ NUXT_PUBLIC_BASE_CDN: ${CDN_URL:-http://localhost:9000}
NUXT_PUBLIC_BASE_URL: ${FRONTEND_URL:-http://localhost:8200}
ports:
diff --git a/docs/README.md b/docs/README.md
index 5bf91cf5..e4f10866 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -333,7 +333,7 @@ Request
β”œβ”€> gin.Recovery() # Panic recovery
β”‚
β”œβ”€> CORS Middleware # Cross-origin handling
- β”‚ β”œβ”€> Origin: DOMAIN_CLIENT
+ β”‚ β”œβ”€> Origin: FRONTEND_URL
β”‚ β”œβ”€> Methods: GET, POST, PUT, PATCH, DELETE, OPTIONS
β”‚ β”œβ”€> Credentials: true
β”‚ └─> Headers: Authorization, Content-Type, etc.
@@ -1843,7 +1843,7 @@ node.Content = SanitizeHTML(userInput)
// CORS middleware configuration
router.Use(cors.New(cors.Config{
- AllowOrigins: []string{os.Getenv("DOMAIN_CLIENT")},
+ AllowOrigins: []string{os.Getenv("FRONTEND_URL")},
AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"},
AllowHeaders: []string{"Origin", "Content-Type", "Authorization"},
ExposeHeaders: []string{"Content-Length"},
diff --git a/docs/setup.md b/docs/setup.md
index 7ef6b0e1..ee2b5d6b 100644
--- a/docs/setup.md
+++ b/docs/setup.md
@@ -92,12 +92,12 @@ The port on which the backend API listens.
FRONTEND_URL: https://example.com
```
-When `FRONTEND_URL` is defined, `DOMAIN_CLIENT` and `COOKIE_DOMAIN` will be automatically derived at startup.
+When `FRONTEND_URL` is defined, `FRONTEND_URL` and `COOKIE_DOMAIN` will be automatically derived at startup.
**Legacy variables (still supported, but not recommended):**
```yml
-DOMAIN_CLIENT: http://localhost:8200
+FRONTEND_URL: http://localhost:8200
COOKIE_DOMAIN: localhost
```
diff --git a/ecosystem.config.js b/ecosystem.config.js
index 244b89ae..cc160654 100644
--- a/ecosystem.config.js
+++ b/ecosystem.config.js
@@ -6,13 +6,20 @@ module.exports = {
cwd: './backend',
env: {
PORT: 8201,
- DOMAIN_CLIENT: 'https://alexandrie-hub.fr',
+ FRONTEND_URL: 'https://alexandrie-hub.fr',
+ COOKIE_DOMAIN: 'alexandrie-hub.fr',
+
MINIO_ENDPOINT: 'cdn.alexandrie-hub.fr',
+ MINIO_PUBLIC_URL: 'https://cdn.alexandrie-hub.fr',
MINIO_BUCKET: 'alexandrie',
MINIO_SECURE: 'true',
+
+ DATABASE_HOST: 'mysql',
+ DATABASE_PORT: 3306,
+ DATABASE_NAME: 'alexandrie',
+
CPWD: './backend/',
CONFIG_CPWD: '',
- COOKIE_DOMAIN: 'alexandrie-hub.fr',
GIN_MODE: 'release',
},
},