A docs portal at /docs and a client developer's guide
The manual the binary carries, rendered on the client port: a sidebar of the documents in the console's reading order (now one list, llmgw.Manual, for both), heading anchors, links between documents kept in the portal and links to files outside the binary sent to the repository, no script. Public by default; landing.docs_sign_in sends visitors to sign in first. docs/clients.md shows the official OpenAI and Anthropic SDKs against llmgw in Python, TypeScript, Go and curl, with llmgw's headers; the portal's index, the landing page and the account page link to it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
e59ff52932
commit
bd439aca29
17 files changed
+1328
-56
No files matched your search
@@ -0,0 +1,48 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/config"
|
||||
)
|
||||
|
||||
func docsRouter(t *testing.T, signIn bool) http.Handler {
|
||||
t.Helper()
|
||||
cfg := baseConfig(config.Endpoint{ID: "a", URL: "http://127.0.0.1:1", Models: []string{"m"}})
|
||||
cfg.Auth.Enabled = true
|
||||
cfg.Auth.Store = filepath.Join(t.TempDir(), "store.db")
|
||||
cfg.Landing.DocsSignIn = signIn
|
||||
return newTestRouter(t, cfg).Handler()
|
||||
}
|
||||
|
||||
// The docs are public by default on a gateway with keys: the client guide is
|
||||
// for the person who has none yet, so asking for one first defeats it.
|
||||
func TestTheDocsAreServedWithoutAKey(t *testing.T) {
|
||||
h := docsRouter(t, false)
|
||||
for _, path := range []string{"/docs", "/docs/clients"} {
|
||||
w := httptest.NewRecorder()
|
||||
h.ServeHTTP(w, httptest.NewRequest(http.MethodGet, path, nil))
|
||||
if w.Code != http.StatusOK || !strings.Contains(w.Body.String(), "llmgw docs") {
|
||||
t.Errorf("%s: %d %.200s", path, w.Code, w.Body.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDocsSignInSendsAVisitorToSignIn(t *testing.T) {
|
||||
h := docsRouter(t, true)
|
||||
for _, path := range []string{"/docs", "/docs/install"} {
|
||||
w := httptest.NewRecorder()
|
||||
h.ServeHTTP(w, httptest.NewRequest(http.MethodGet, path, nil))
|
||||
// The session guard, not the key check: a browser has no key.
|
||||
if strings.Contains(w.Body.String(), "api key") {
|
||||
t.Errorf("%s asked a browser for an API key", path)
|
||||
}
|
||||
if w.Code != http.StatusSeeOther || w.Header().Get("Location") != "/login" {
|
||||
t.Errorf("%s: %d to %q, want a redirect to /login", path, w.Code, w.Header().Get("Location"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -210,6 +210,11 @@ func (r *Router) Handler() http.Handler {
|
||||
pages.RegisterAdminGuard(mux, r.store, r.guardLibrary)
|
||||
}
|
||||
pages.Register(mux)
|
||||
// The docs portal, with the menu of whoever is signed in, and only to
|
||||
// them when the site asked for that.
|
||||
docs := pages.DocsPage(web.Docs(version.Version, true), r.landing.DocsSignIn)
|
||||
mux.HandleFunc("GET /docs", docs)
|
||||
mux.HandleFunc("GET /docs/{doc}", docs)
|
||||
r.registerChat(mux, pages)
|
||||
// An organization's own page, for the people who manage it.
|
||||
pages.RegisterOrgPages(mux, r.store, r.acct)
|
||||
@@ -261,18 +266,29 @@ func (r *Router) Handler() http.Handler {
|
||||
Catalog: r.catalogAdmin, Fleet: r.clusterView,
|
||||
})
|
||||
}
|
||||
} else {
|
||||
// No accounts, so nobody to show a menu to or to send to sign in.
|
||||
docs := web.Docs(version.Version, false)
|
||||
mux.HandleFunc("GET /docs", docs)
|
||||
mux.HandleFunc("GET /docs/{doc}", docs)
|
||||
}
|
||||
|
||||
if r.auth == nil {
|
||||
return mux
|
||||
}
|
||||
exempt := []string{"/health", "/ready", "/leader", "/", "/about", "/_static/", "/claim/",
|
||||
"/signup", "/login", "/login/", "/logout", "/profile", "/profile/", "/scim/",
|
||||
"/admin", "/admin/", "/chat", "/chat/", "/org", "/org/", "/setup/"}
|
||||
// The docs are public unless the site said otherwise, and then guarded by
|
||||
// the session check in front of them — or, on a gateway with keys and no
|
||||
// accounts to sign in to, by the key like any other path.
|
||||
if !r.landing.DocsSignIn || r.accounts != nil {
|
||||
exempt = append(exempt, "/docs", "/docs/")
|
||||
}
|
||||
// Wrapping the whole mux rather than checking inside each handler: adding a
|
||||
// route must not be able to add an unauthenticated one by omission. Health
|
||||
// stays open because a load balancer has no key.
|
||||
return auth.Middleware(r.auth, r.log,
|
||||
"/health", "/ready", "/leader", "/", "/about", "/_static/", "/claim/",
|
||||
"/signup", "/login", "/login/", "/logout", "/profile", "/profile/", "/scim/",
|
||||
"/admin", "/admin/", "/chat", "/chat/", "/org", "/org/", "/setup/")(mux)
|
||||
return auth.Middleware(r.auth, r.log, exempt...)(mux)
|
||||
}
|
||||
|
||||
// parsedRequest is what the router needs from a request. Everything else in the
|
||||
|
||||
Reference in new issue
Block a user