34bf5b5ac2
- embedded Go templates + vanilla ES-module JS + hand-written CSS, no build step
- exact §10 beige light / dark design tokens, square edges (radius 2px),
system font stack, visible focus rings
- theme toggle persisted to localStorage and the user profile
- login/register/change-password pages wired to the auth API
- profile page: avatar upload (image-sniffed, old file cleanup), bio,
contacts, arbitrary extra key/value fields, optimistic-concurrency 409
- role-based top navigation with placeholders for later-phase areas
- GET /files/{id} with scope-based access (session) or signed token (§5.1)
- security headers incl. CSP without unsafe-inline scripts
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
69 lines
1.4 KiB
Go
69 lines
1.4 KiB
Go
// Command app is the Bounty Board main service.
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log/slog"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
"time"
|
|
|
|
"bountyboard/internal/auth"
|
|
"bountyboard/internal/config"
|
|
"bountyboard/internal/files"
|
|
httpx "bountyboard/internal/http"
|
|
"bountyboard/internal/metrics"
|
|
"bountyboard/internal/store"
|
|
)
|
|
|
|
func main() {
|
|
if err := run(); err != nil {
|
|
fmt.Fprintln(os.Stderr, "fatal:", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func run() error {
|
|
if err := config.LoadDotEnv(".env"); err != nil {
|
|
return fmt.Errorf("load .env: %w", err)
|
|
}
|
|
cfg, err := config.Load()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
log := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo}))
|
|
slog.SetDefault(log)
|
|
|
|
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
|
defer stop()
|
|
|
|
st, err := store.Connect(ctx, cfg, log)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer func() {
|
|
closeCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
defer cancel()
|
|
if err := st.Close(closeCtx); err != nil {
|
|
log.Error("close mongo", "err", err)
|
|
}
|
|
}()
|
|
|
|
if err := auth.EnsureBootstrapAdmin(ctx, st, cfg, log); err != nil {
|
|
return err
|
|
}
|
|
|
|
reg := metrics.NewRegistry()
|
|
srv := httpx.New(cfg, log, reg, st, files.NewStore(st.DB, cfg.MaxUploadMB))
|
|
srv.AddReadinessCheck(httpx.ReadinessCheck{
|
|
Name: "mongo",
|
|
Required: true,
|
|
Probe: st.Ping,
|
|
})
|
|
|
|
return srv.Run(ctx)
|
|
}
|