From 0da3a1ffb94053ed691d453c92129a6f702503be Mon Sep 17 00:00:00 2001 From: Asaf Gartner Date: Tue, 4 May 2021 16:35:30 +0300 Subject: [PATCH] Added a 404 path for assets that doesn't render the full template --- src/website/routes.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/website/routes.go b/src/website/routes.go index a278545..61e6a6a 100644 --- a/src/website/routes.go +++ b/src/website/routes.go @@ -166,16 +166,21 @@ func ProjectCSS(c *RequestContext) ResponseData { } func FourOhFour(c *RequestContext) ResponseData { - templateData := struct { - templates.BaseData - Wanted string - }{ - BaseData: getBaseData(c), - Wanted: c.FullUrl(), - } var res ResponseData res.StatusCode = http.StatusNotFound - res.WriteTemplate("404.html", templateData, c.Perf) + + if c.Req.Header["Accept"] != nil && strings.Contains(c.Req.Header["Accept"][0], "text/html") { + templateData := struct { + templates.BaseData + Wanted string + }{ + BaseData: getBaseData(c), + Wanted: c.FullUrl(), + } + res.WriteTemplate("404.html", templateData, c.Perf) + } else { + res.Write([]byte("Not Found")) + } return res }