Monorepo for Tangled tangled.org
761
fork

Configure Feed

Select the types of activity you want to include in your feed.

knotserver: add motd

Signed-off-by: Anirudh Oppiliappan <anirudh@tangled.org>

authored by

Anirudh Oppiliappan and committed by
Tangled
a69f6eb4 d8144484

+36 -1
+13
knotserver/motd
··· 1 + 2 + ____ _.-' 3 + _.---..__ .-'____i-+'_.-' 4 + .__ .-'_.---.._i'.-'____.--' 5 + .__""--: .'__..--"_.' "" '.'. __ 6 + ""-: :.___..--" .---._____i.i--""__ 7 + ...___: :________.-"""-.______..--"" 8 + ...____: '.______.-"""-.__.-' 9 + '-.___.' 10 + 11 + This is a knot server. More info at https://docs.tangled.org/knot-self-hosting-guide.html 12 + 13 + Most API routes are under /xrpc/
+23 -1
knotserver/router.go
··· 2 2 3 3 import ( 4 4 "context" 5 + _ "embed" 5 6 "fmt" 6 7 "log/slog" 7 8 "net/http" 8 9 "strings" 10 + "sync" 9 11 10 12 "github.com/go-chi/chi/v5" 11 13 "tangled.org/core/idresolver" ··· 19 21 "tangled.org/core/xrpc/serviceauth" 20 22 ) 21 23 24 + //go:embed motd 25 + var defaultMotd []byte 26 + 22 27 type Knot struct { 23 28 c *config.Config 24 29 db *db.DB ··· 27 32 l *slog.Logger 28 33 n *notifier.Notifier 29 34 resolver *idresolver.Resolver 35 + motd []byte 36 + motdMu sync.RWMutex 30 37 } 31 38 32 39 func Setup(ctx context.Context, c *config.Config, db *db.DB, e *rbac.Enforcer, jc *jetstream.JetstreamClient, n *notifier.Notifier) (http.Handler, error) { ··· 38 45 jc: jc, 39 46 n: n, 40 47 resolver: idresolver.DefaultResolver(c.Server.PlcUrl), 48 + motd: defaultMotd, 41 49 } 42 50 43 51 err := e.AddKnot(rbac.ThisServer) ··· 76 84 r.Use(h.RequestLogger) 77 85 78 86 r.Get("/", func(w http.ResponseWriter, r *http.Request) { 79 - w.Write([]byte("This is a knot server. More info at https://tangled.sh")) 87 + w.Write(h.GetMotdContent()) 80 88 }) 81 89 82 90 r.Route("/{did}", func(r chi.Router) { ··· 102 110 r.Get("/events", h.Events) 103 111 104 112 return r 113 + } 114 + 115 + // SetMotdContent sets custom MOTD content, replacing the embedded default. 116 + func (h *Knot) SetMotdContent(content []byte) { 117 + h.motdMu.Lock() 118 + defer h.motdMu.Unlock() 119 + h.motd = content 120 + } 121 + 122 + // GetMotdContent returns the current MOTD content. 123 + func (h *Knot) GetMotdContent() []byte { 124 + h.motdMu.RLock() 125 + defer h.motdMu.RUnlock() 126 + return h.motd 105 127 } 106 128 107 129 func (h *Knot) XrpcRouter() http.Handler {