MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / ServeHTTP

Method ServeHTTP

pkg/webui/template.go:182–223  ·  view source on GitHub ↗

ServeHTTP renders the web UI.

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

180
181// ServeHTTP renders the web UI.
182func (t *AppTemplate) ServeHTTP(w http.ResponseWriter, r *http.Request) {
183 ctx := r.Context()
184 templateData := ctx.Value(templateDataKey).(TemplateData)
185 templateData.CSRFToken = csrf.Token(r)
186 var cspNonce string
187 if v, ok := ctx.Value(nonceKey).(string); ok {
188 cspNonce = v
189 }
190 cssFiles := make([]string, len(templateData.CSSFiles))
191 for i, cssFile := range templateData.CSSFiles {
192 if hashedFile, ok := hashedFiles[cssFile]; ok {
193 cssFiles[i] = hashedFile
194 } else {
195 cssFiles[i] = cssFile
196 }
197 }
198 templateData.CSSFiles = cssFiles
199 jsFiles := make([]string, len(templateData.JSFiles))
200 for i, jsFile := range templateData.JSFiles {
201 if hashedFile, ok := hashedFiles[jsFile]; ok {
202 jsFiles[i] = hashedFile
203 } else {
204 jsFiles[i] = jsFile
205 }
206 }
207 templateData.JSFiles = jsFiles
208 pageData := ctx.Value(pageDataKey)
209 if err := webhandlers.RetrieveError(r); err != nil {
210 pageData = map[string]any{
211 "error": err,
212 }
213 }
214 if err := t.template.Execute(w, Data{
215 TemplateData: templateData,
216 AppConfig: ctx.Value(appConfigKey),
217 ExperimentalFeatures: experimental.AllFeatures(ctx),
218 PageData: pageData,
219 CSPNonce: cspNonce,
220 }); err != nil {
221 log.FromContext(ctx).WithError(err).Warn("Failed to execute template")
222 }
223}

Callers

nothing calls this directly

Calls 9

RetrieveErrorFunction · 0.92
AllFeaturesFunction · 0.92
FromContextFunction · 0.92
ContextMethod · 0.65
TokenMethod · 0.65
ExecuteMethod · 0.65
WarnMethod · 0.65
WithErrorMethod · 0.65
ValueMethod · 0.45

Tested by

no test coverage detected