Fix BASE_URL config loading, add tasks/projects; robust .env path resolution
- Config: try ENV_FILE, .env, ../.env for loading; trim trailing slash from BaseURL - Log BASE_URL at server startup for verification - .env.example: document BASE_URL - Tasks, projects, tags, migrations and related API/handlers Made-with: Cursor
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"bufio"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
@@ -21,7 +22,7 @@ type Config struct {
|
||||
}
|
||||
|
||||
func Load() *Config {
|
||||
loadEnvFile(".env")
|
||||
loadEnvFromPath()
|
||||
|
||||
port := getEnv("SERVER_PORT", "8080")
|
||||
jwtSecret := getEnv("JWT_SECRET", "dev-secret-change-me")
|
||||
@@ -41,7 +42,7 @@ func Load() *Config {
|
||||
RedisAddr: os.Getenv("REDIS_ADDR"),
|
||||
ServerPort: port,
|
||||
Env: env,
|
||||
BaseURL: getEnv("BASE_URL", "http://localhost:"+port),
|
||||
BaseURL: strings.TrimSuffix(getEnv("BASE_URL", "http://localhost:"+port), "/"),
|
||||
CORSOrigins: corsOrigins,
|
||||
RateLimitRPS: rateRPS,
|
||||
RateLimitBurst: rateBurst,
|
||||
@@ -82,6 +83,24 @@ func parseInt(s string, def int) int {
|
||||
return v
|
||||
}
|
||||
|
||||
func loadEnvFromPath() {
|
||||
if p := os.Getenv("ENV_FILE"); p != "" {
|
||||
loadEnvFile(p)
|
||||
return
|
||||
}
|
||||
cwd, _ := os.Getwd()
|
||||
for _, p := range []string{".env", "../.env"} {
|
||||
full := filepath.Join(cwd, p)
|
||||
if f, err := os.Open(full); err == nil {
|
||||
f.Close()
|
||||
loadEnvFile(full)
|
||||
return
|
||||
}
|
||||
}
|
||||
// Fallback: try current dir as-is (for relative paths)
|
||||
loadEnvFile(".env")
|
||||
}
|
||||
|
||||
func loadEnvFile(path string) {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user