blob: bb130a1869e4dc11ebefb48d8c8366bc02001c5d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
package main
import (
"auth-proxy/config"
"auth-proxy/database"
"auth-proxy/handlers"
"auth-proxy/logging"
"auth-proxy/middleware"
"auth-proxy/router"
"auth-proxy/worker"
"net/http"
"os"
"github.com/joho/godotenv"
)
func main() {
// Initialize loggers
logging.InitLoggers()
// Load .env file
if err := godotenv.Load(); err != nil {
logging.AppLog.Info("No .env file found, using environment variables")
}
// Initialize path configurations
config.Init()
// Initialize database
database.InitDB()
defer database.CloseDB()
// Initialize and start the worker pool
pool := worker.NewWorkerPool()
defer worker.Close(pool)
handlers.SetWorkerPool(pool)
// --- Secret Key Validation ---
sessionSecret := os.Getenv("SESSION_SECRET")
if sessionSecret == "" {
logging.AppLog.Warn("SESSION_SECRET environment variable not set. Using default key. THIS IS NOT SAFE FOR PRODUCTION.")
}
xsrfSecret := os.Getenv("XSRF_SECRET_KEY")
if xsrfSecret == "" {
logging.AppLog.Error("XSRF_SECRET_KEY environment variable not set")
os.Exit(1)
}
// Get target URL for proxy
targetURL := os.Getenv("TARGET_URL")
if targetURL == "" {
logging.AppLog.Error("TARGET_URL environment variable not set")
os.Exit(1)
}
// Create the main handler
mainRouter := router.NewRouter()
// Start periodic background tasks
go router.StartBackgroundTasks(pool, middleware.NewRateLimiter())
// Get server port
port := os.Getenv("LISTEN_PORT")
if port == "" {
port = "8080"
}
listenAddr := ":" + port
// --- Start Server ---
logging.AppLog.Info("Server starting on " + listenAddr)
if err := http.ListenAndServe(listenAddr, mainRouter); err != nil {
logging.AppLog.Error("Server failed to start", "error", err)
os.Exit(1)
}
}
|