ServeHTTP renders the web UI.
(w http.ResponseWriter, r *http.Request)
| 180 | |
| 181 | // ServeHTTP renders the web UI. |
| 182 | func (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 | } |
nothing calls this directly
no test coverage detected