Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ A web application for resolving and inspecting OpenID Federation trust chains.

The server will start on `http://localhost:8080`

## Environment Variables

| Variable | Description | Format | Default |
|----------------------|-----------------------------------------------|-------------------------------------------------|----------|
| `PROXY_HEADER` | Header name for client IP behind proxy | String (e.g., `X-Forwarded-For`) | Empty |
| `CACHE_MAX_LIFETIME` | Maximum lifetime for cached entity statements | Go duration string (e.g., `1h`, `3600s`, `24h`) | No limit |

**Example:**
```bash
export CACHE_MAX_LIFETIME=1h
./server
```

## Usage

1. Open your browser to `http://localhost:8080`
Expand Down
54 changes: 37 additions & 17 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,43 @@ import (
"net/http"
"os"
"path/filepath"
"time"

"github.com/go-oidfed/resolve-browser/internal/handlers"
"github.com/go-oidfed/lib/cache"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/filesystem"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/fiber/v2/middleware/recover"

"github.com/go-oidfed/resolve-browser/internal/handlers"
)

func main() {
app := fiber.New(fiber.Config{
ProxyHeader: os.Getenv("PROXY_HEADER"),
ErrorHandler: func(c *fiber.Ctx, err error) error {
code := fiber.StatusInternalServerError
if e, ok := err.(*fiber.Error); ok {
code = e.Code
}
return c.Status(code).JSON(map[string]interface{}{
"error": err.Error(),
})
app := fiber.New(
fiber.Config{
ProxyHeader: os.Getenv("PROXY_HEADER"),
ErrorHandler: func(c *fiber.Ctx, err error) error {
code := fiber.StatusInternalServerError
if e, ok := err.(*fiber.Error); ok {
code = e.Code
}
return c.Status(code).JSON(
map[string]interface{}{
"error": err.Error(),
},
)
},
},
})
)

if cacheMaxLifetime := os.Getenv("CACHE_MAX_LIFETIME"); cacheMaxLifetime != "" {
if duration, err := time.ParseDuration(cacheMaxLifetime); err == nil && duration > 0 {
cache.SetMaxLifetime(duration)
log.Printf("Cache max lifetime set to: %v", duration)
} else if err != nil {
log.Printf("Warning: Invalid CACHE_MAX_LIFETIME value '%s': %v", cacheMaxLifetime, err)
}
}

app.Use(logger.New())
app.Use(recover.New())
Expand All @@ -39,11 +55,15 @@ func main() {
staticPath = filepath.Join(cwd, "frontend", "static")
}

app.Use("/", filesystem.New(filesystem.Config{
Root: http.Dir(staticPath),
Browse: false,
MaxAge: 3600,
}))
app.Use(
"/", filesystem.New(
filesystem.Config{
Root: http.Dir(staticPath),
Browse: false,
MaxAge: 3600,
},
),
)

api := app.Group("/api")
api.Post("/resolve", handlers.ResolveHandler)
Expand Down
Loading