0bcb96c442
web/handlers/reach.go: GET /reach (list), GET /reach/new (form),
GET /reach/{id} (detail), POST /reach (atomic Reach+Stash create
per D-071, redirect 302). Labels "Create a Reach" (not the banned
legacy word). G-027 validation (non-empty, <=128, no path separators,
no template syntax). 3 Reach templates extend base.html.
reach_test.go: httptest for all 4 routes + atomic create + 400/409
error paths + rendered-HTML lexicon check on BOTH 200 and error bodies
(G-026). handlers/server.go: clone-per-page template pattern (avoids
content-block collision across pages). Coverage 81.2% on web/handlers.
---ci---
project: oy
phase: 1
milestone: v0.6
status: execute
---/ci---
43 lines
891 B
Go
43 lines
891 B
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
|
|
"github.com/oy/openyield/web/handlers"
|
|
"github.com/oy/openyield/web/store"
|
|
)
|
|
|
|
func runServer() {
|
|
port := os.Getenv("PORT")
|
|
if port == "" {
|
|
port = "8080"
|
|
}
|
|
|
|
mux := http.NewServeMux()
|
|
|
|
srv, err := handlers.New(store.NewStore(), "web/templates")
|
|
if err != nil {
|
|
log.Fatalf("init handlers: %v", err)
|
|
}
|
|
srv.Register(mux)
|
|
|
|
// Home page (rendered via the handlers' page machinery too).
|
|
mux.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Path != "/" {
|
|
http.NotFound(w, r)
|
|
return
|
|
}
|
|
srv.RenderHome(w, nil)
|
|
})
|
|
|
|
mux.Handle("GET /static/", http.StripPrefix("/static/", http.FileServer(http.Dir("web/static"))))
|
|
|
|
server := &http.Server{Addr: ":" + port, Handler: mux}
|
|
log.Printf("OpenYield web on :%s", port)
|
|
if err := server.ListenAndServe(); err != nil {
|
|
log.Fatalf("server: %v", err)
|
|
}
|
|
}
|