MCPcopy
hub / github.com/livebud/bud / render

Method render

package/budhttp/budsvr/handler.go:60–90  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

58var _ http.Handler = (*Handler)(nil)
59
60func (h *Handler) render(w http.ResponseWriter, r *http.Request) {
61 // Read the body
62 body, err := io.ReadAll(r.Body)
63 if err != nil {
64 http.Error(w, err.Error(), http.StatusBadRequest)
65 return
66 }
67 // Load the props
68 var props map[string]interface{}
69 if err := json.Unmarshal(body, &props); err != nil {
70 http.Error(w, err.Error(), http.StatusBadRequest)
71 return
72 }
73 script, err := fs.ReadFile(h.fsys, "bud/view/_ssr.js")
74 if err != nil {
75 if errors.Is(err, fs.ErrNotExist) {
76 http.Error(w, err.Error(), http.StatusNotFound)
77 return
78 }
79 http.Error(w, err.Error(), http.StatusInternalServerError)
80 return
81 }
82 route := "/" + r.URL.Query().Get("route")
83 expr := fmt.Sprintf(`%s; bud.render(%q, %s)`, script, route, body)
84 result, err := h.vm.Eval("_ssr.js", expr)
85 if err != nil {
86 http.Error(w, err.Error(), http.StatusInternalServerError)
87 return
88 }
89 w.Write([]byte(result))
90}
91
92func (h *Handler) open(w http.ResponseWriter, r *http.Request) {
93 path := r.URL.Query().Get("path")

Callers

nothing calls this directly

Calls 7

UnmarshalMethod · 0.80
IsMethod · 0.80
QueryMethod · 0.80
ErrorMethod · 0.65
GetMethod · 0.65
EvalMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected