chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
# Orchbase Environment Variables
|
||||
# Copy this file to .env and customize the values
|
||||
#
|
||||
# ⚠️ NOTE: This is a PostgreSQL fork of PocketBase.
|
||||
# SQLite is NOT supported by this codebase.
|
||||
# Use the original PocketBase for SQLite support.
|
||||
|
||||
# ============================================================
|
||||
# DATABASE CONFIGURATION (PostgreSQL Only)
|
||||
# ============================================================
|
||||
# Database type: "sqlite", "postgres" or "mysql"
|
||||
DB_TYPE=postgres
|
||||
# PostgreSQL connection URL (REQUIRED)
|
||||
# Format: postgres://user:password@host:port/database?sslmode=disable
|
||||
POSTGRES_URL=postgres://user:pass@127.0.0.1:6432/postgres?sslmode=disable
|
||||
|
||||
# PostgreSQL database names
|
||||
# These databases will be created automatically if they don't exist
|
||||
POSTGRES_DATA_DB=pb-data
|
||||
POSTGRES_AUX_DB=pb-auxiliary
|
||||
|
||||
# MySQL Configuration (used when DB_TYPE=mysql)
|
||||
MYSQL_DSN="root:password@tcp(127.0.0.1:3306)/"
|
||||
MYSQL_DATA_DB=pb_data
|
||||
MYSQL_AUX_DB=pb_auxiliary
|
||||
|
||||
# Data directory for file storage (also used for SQLite db files)
|
||||
#PB_DATA_DIR=./pb_data
|
||||
|
||||
# ============================================================
|
||||
# SECURITY CONFIGURATION
|
||||
# ============================================================
|
||||
|
||||
# Encryption key for app settings (including S3 credentials)
|
||||
# IMPORTANT: This must be EXACTLY 32 characters for AES-256 encryption
|
||||
#
|
||||
# To generate a secure key, run one of these commands:
|
||||
# openssl rand -base64 32 | head -c 32
|
||||
# head -c 32 /dev/urandom | base64 | head -c 32
|
||||
#
|
||||
# WARNING:
|
||||
# - Keep this key secret and never commit it to version control
|
||||
# - If you lose this key, you will not be able to decrypt your settings
|
||||
# - Changing this key will require re-entering all encrypted settings
|
||||
#
|
||||
# Example (DO NOT use this in production):
|
||||
# PB_ENCRYPTION_KEY=your-32-character-secret-key123
|
||||
|
||||
# ============================================================
|
||||
# OPTIONAL CONFIGURATION
|
||||
# ============================================================
|
||||
|
||||
# Data directory path for file storage (default: ./pb_data)
|
||||
# Note: Even with PostgreSQL, files are still stored locally
|
||||
PB_DATA_DIR=./pb_data
|
||||
|
||||
# Public directory for static files (default: ./pb_public)
|
||||
# PB_PUBLIC_DIR=./pb_public
|
||||
|
||||
# Hooks directory for JavaScript hooks (default: ./pb_hooks)
|
||||
# PB_HOOKS_DIR=./pb_hooks
|
||||
|
||||
# Enable realtime bridge for horizontal scaling (default: true)
|
||||
# PB_REALTIME_BRIDGE=true
|
||||
|
||||
# Debug mode - prints database configuration on startup
|
||||
# PB_DEBUG=true
|
||||
|
||||
# Set to false to disable the admin UI dashboard
|
||||
# PB_ADMIN_UI_ENABLED=true
|
||||
@@ -0,0 +1,7 @@
|
||||
# ignore everything
|
||||
/*
|
||||
|
||||
# exclude from the ignore filter
|
||||
!.gitignore
|
||||
!.env.example
|
||||
!main.go
|
||||
@@ -0,0 +1,181 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/pocketbase/pocketbase"
|
||||
"github.com/pocketbase/pocketbase/apis"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"github.com/pocketbase/pocketbase/plugins/ghupdate"
|
||||
"github.com/pocketbase/pocketbase/plugins/jsvm"
|
||||
"github.com/pocketbase/pocketbase/plugins/migratecmd"
|
||||
"github.com/pocketbase/pocketbase/tools/hook"
|
||||
"github.com/pocketbase/pocketbase/tools/osutils"
|
||||
|
||||
// Import migrations to ensure they are registered
|
||||
_ "github.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
// EncryptionEnvName is the name of the environment variable that holds the 32-char encryption key
|
||||
const EncryptionEnvName = "PB_ENCRYPTION_KEY"
|
||||
|
||||
func main() {
|
||||
// Load .env file if it exists
|
||||
// This allows configuration through a .env file
|
||||
godotenv.Load()
|
||||
|
||||
// Get database configuration from environment variables
|
||||
dbConfig := GetDBConfigFromEnv()
|
||||
|
||||
// Print the configuration (useful for debugging)
|
||||
if os.Getenv("PB_DEBUG") == "true" {
|
||||
dbConfig.PrintConfig()
|
||||
}
|
||||
|
||||
// Build PocketBase configuration
|
||||
pbConfig := pocketbase.Config{
|
||||
DefaultEncryptionEnv: EncryptionEnvName,
|
||||
DefaultDataDir: dbConfig.GetDataDir(),
|
||||
DBConnect: dbConfig.GetDBConnectFunc(),
|
||||
}
|
||||
|
||||
// If using PostgreSQL or MySQL, also set the auxiliary settings
|
||||
if dbConfig.Type == DBTypePostgres {
|
||||
pbConfig.DefaultPostgresURL = dbConfig.PostgresURL
|
||||
pbConfig.DefaultPostgresDataDb = dbConfig.PostgresDataDB
|
||||
pbConfig.DefaultPostgresAuxDb = dbConfig.PostgresAuxDB
|
||||
} else if dbConfig.Type == DBTypeMysql {
|
||||
// Pass MySQL DB names via the existing structure fields
|
||||
pbConfig.DefaultPostgresDataDb = dbConfig.MysqlDataDB
|
||||
pbConfig.DefaultPostgresAuxDb = dbConfig.MysqlAuxDB
|
||||
}
|
||||
|
||||
// Initialize app with the configuration
|
||||
app := pocketbase.NewWithConfig(pbConfig)
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Optional plugin flags:
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
var hooksDir string
|
||||
app.RootCmd.PersistentFlags().StringVar(
|
||||
&hooksDir,
|
||||
"hooksDir",
|
||||
os.Getenv("PB_HOOKS_DIR"),
|
||||
"the directory with the JS app hooks",
|
||||
)
|
||||
|
||||
var hooksWatch bool
|
||||
app.RootCmd.PersistentFlags().BoolVar(
|
||||
&hooksWatch,
|
||||
"hooksWatch",
|
||||
true,
|
||||
"auto restart the app on pb_hooks file change; it has no effect on Windows",
|
||||
)
|
||||
|
||||
var hooksPool int
|
||||
app.RootCmd.PersistentFlags().IntVar(
|
||||
&hooksPool,
|
||||
"hooksPool",
|
||||
15,
|
||||
"the total prewarm goja.Runtime instances for the JS app hooks execution",
|
||||
)
|
||||
|
||||
var migrationsDir string
|
||||
app.RootCmd.PersistentFlags().StringVar(
|
||||
&migrationsDir,
|
||||
"migrationsDir",
|
||||
"",
|
||||
"the directory with the user defined migrations",
|
||||
)
|
||||
|
||||
var automigrate bool
|
||||
app.RootCmd.PersistentFlags().BoolVar(
|
||||
&automigrate,
|
||||
"automigrate",
|
||||
true,
|
||||
"enable/disable auto migrations",
|
||||
)
|
||||
|
||||
var publicDir string
|
||||
app.RootCmd.PersistentFlags().StringVar(
|
||||
&publicDir,
|
||||
"publicDir",
|
||||
defaultPublicDir(),
|
||||
"the directory to serve static files",
|
||||
)
|
||||
|
||||
var indexFallback bool
|
||||
app.RootCmd.PersistentFlags().BoolVar(
|
||||
&indexFallback,
|
||||
"indexFallback",
|
||||
true,
|
||||
"fallback the request to index.html on missing static path, e.g. when pretty urls are used with SPA",
|
||||
)
|
||||
|
||||
app.RootCmd.ParseFlags(os.Args[1:])
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Plugins and hooks:
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
// load jsvm (pb_hooks and pb_migrations)
|
||||
jsvm.MustRegister(app, jsvm.Config{
|
||||
MigrationsDir: migrationsDir,
|
||||
HooksDir: hooksDir,
|
||||
HooksWatch: hooksWatch,
|
||||
HooksPoolSize: hooksPool,
|
||||
})
|
||||
|
||||
// migrate command (with js templates)
|
||||
migratecmd.MustRegister(app, app.RootCmd, migratecmd.Config{
|
||||
TemplateLang: migratecmd.TemplateLangJS,
|
||||
Automigrate: automigrate,
|
||||
Dir: migrationsDir,
|
||||
})
|
||||
|
||||
// GitHub selfupdate
|
||||
ghupdate.MustRegister(app, app.RootCmd, ghupdate.Config{})
|
||||
|
||||
// static route to serves files from the provided public dir
|
||||
// (if publicDir exists and the route path is not already defined)
|
||||
app.OnServe().Bind(&hook.Handler[*core.ServeEvent]{
|
||||
Func: func(e *core.ServeEvent) error {
|
||||
if !e.Router.HasRoute(http.MethodGet, "/{path...}") {
|
||||
e.Router.GET("/{path...}", apis.Static(os.DirFS(publicDir), indexFallback))
|
||||
}
|
||||
|
||||
return e.Next()
|
||||
},
|
||||
Priority: 999, // execute as latest as possible to allow users to provide their own route
|
||||
})
|
||||
|
||||
// Print database info on startup
|
||||
app.OnServe().Bind(&hook.Handler[*core.ServeEvent]{
|
||||
Func: func(e *core.ServeEvent) error {
|
||||
log.Printf("Starting with database type: %s", dbConfig.Type)
|
||||
return e.Next()
|
||||
},
|
||||
Priority: -999,
|
||||
})
|
||||
|
||||
if err := app.Start(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// the default pb_public dir location is relative to the executable
|
||||
func defaultPublicDir() string {
|
||||
if os.Getenv("PB_PUBLIC_DIR") != "" {
|
||||
return os.Getenv("PB_PUBLIC_DIR")
|
||||
}
|
||||
if osutils.IsProbablyGoRun() {
|
||||
return "./pb_public"
|
||||
}
|
||||
|
||||
return filepath.Join(os.Args[0], "../pb_public")
|
||||
}
|
||||
Reference in New Issue
Block a user