|
|
@ -22,7 +22,24 @@ func main() { |
|
|
|
|
|
|
|
|
dsn := os.Getenv("DATABASE_URL") |
|
|
dsn := os.Getenv("DATABASE_URL") |
|
|
if dsn == "" { |
|
|
if dsn == "" { |
|
|
dsn = "postgres://dropzone:dropzone@localhost:15432/dropzone?sslmode=disable" |
|
|
host := os.Getenv("DB_HOST") |
|
|
|
|
|
if host == "" { |
|
|
|
|
|
host = "localhost" |
|
|
|
|
|
} |
|
|
|
|
|
port := os.Getenv("DB_PORT") |
|
|
|
|
|
if port == "" { |
|
|
|
|
|
port = "15432" |
|
|
|
|
|
} |
|
|
|
|
|
name := os.Getenv("DB_NAME") |
|
|
|
|
|
if name == "" { |
|
|
|
|
|
name = "dropzone" |
|
|
|
|
|
} |
|
|
|
|
|
user := os.Getenv("DB_USER") |
|
|
|
|
|
if user == "" { |
|
|
|
|
|
user = "dropzone" |
|
|
|
|
|
} |
|
|
|
|
|
pass := os.Getenv("DB_PASSWORD") |
|
|
|
|
|
dsn = fmt.Sprintf("postgres://%s:%s@%s:%s/%s?sslmode=disable", user, pass, host, port, name) |
|
|
} |
|
|
} |
|
|
jwtSecret := os.Getenv("JWT_SECRET") |
|
|
jwtSecret := os.Getenv("JWT_SECRET") |
|
|
if jwtSecret == "" { |
|
|
if jwtSecret == "" { |
|
|
@ -52,6 +69,10 @@ func main() { |
|
|
r.Use(chimiddleware.Logger) |
|
|
r.Use(chimiddleware.Logger) |
|
|
r.Use(chimiddleware.Recoverer) |
|
|
r.Use(chimiddleware.Recoverer) |
|
|
|
|
|
|
|
|
|
|
|
r.Get("/api/health", func(w http.ResponseWriter, r *http.Request) { |
|
|
|
|
|
w.WriteHeader(http.StatusOK) |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
// Public endpoints
|
|
|
// Public endpoints
|
|
|
r.Post("/api/auth/login", auth.NewLoginHandler(db, jwtSecret)) |
|
|
r.Post("/api/auth/login", auth.NewLoginHandler(db, jwtSecret)) |
|
|
r.Get("/api/files/public", files.PublicListHandler(diskRoot)) |
|
|
r.Get("/api/files/public", files.PublicListHandler(diskRoot)) |
|
|
|