HandleNotFound handles pages not found. In particular, this handler is used when we have no matching route for a request. This also means it's not useful to inject the livereload paraphernalia here.
(templates *template.Template)
| 241 | // when we have no matching route for a request. This also means it's not |
| 242 | // useful to inject the livereload paraphernalia here. |
| 243 | func HandleNotFound(templates *template.Template) httpctx.Handler { |
| 244 | return httpctx.HandlerFunc(func(ctx context.Context, w http.ResponseWriter, r *http.Request) { |
| 245 | w.WriteHeader(http.StatusNotFound) |
| 246 | err := templates.Lookup("404.html").Execute(w, nil) |
| 247 | if err != nil { |
| 248 | logger := termlog.FromContext(ctx) |
| 249 | logger.Shout("Could not execute template: %s", err) |
| 250 | } |
| 251 | }) |
| 252 | } |
| 253 | |
| 254 | // Router constructs the main Devd router that serves all requests |
| 255 | func (dd *Devd) Router(logger termlog.TermLog, templates *template.Template) (http.Handler, error) { |