MCPcopy
hub / github.com/cortesi/devd / HandleNotFound

Function HandleNotFound

server.go:243–252  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

241// when we have no matching route for a request. This also means it's not
242// useful to inject the livereload paraphernalia here.
243func 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
255func (dd *Devd) Router(logger termlog.TermLog, templates *template.Template) (http.Handler, error) {

Callers 1

RouterMethod · 0.85

Calls 1

WriteHeaderMethod · 0.80

Tested by

no test coverage detected