Added our 404 page

This commit is contained in:
Asaf Gartner 2021-05-04 16:23:02 +03:00
parent 47c25207a4
commit 94bd05751e
4 changed files with 38 additions and 4 deletions

View File

@ -13,4 +13,8 @@ var Config = HMNConfig{
MinConn: 2, // Keep these low for dev, high for production MinConn: 2, // Keep these low for dev, high for production
MaxConn: 2, MaxConn: 2,
}, },
Auth: AuthConfig{
CookieDomain: ".handmade.local",
CookieSecure: false,
},
} }

View File

@ -0,0 +1,13 @@
{{ template "base.html" . }}
{{ define "content" }}
<div class="description">
<p>
<span class="big">Hi there, {{ if .User }}{{ .User.Name }}{{ else }}visitor{{ end }}!</span>
</p>
<p>
<span class="big">We couldn't find what you were looking for:</span><br />
{{ .Wanted }}
</p>
</div>
{{ end }}

View File

@ -133,6 +133,16 @@ func (c *RequestContext) URL() *url.URL {
return c.Req.URL return c.Req.URL
} }
func (c *RequestContext) FullUrl() string {
var scheme string // TODO(asaf): BEFORE RELEASE!! Fetch scheme from X-Forwarded-* headers or Forwarded header
if c.Req.TLS != nil {
scheme = "https://"
} else {
scheme = "http://"
}
return scheme + c.Req.Host + c.Req.URL.String()
}
func (c *RequestContext) GetFormValues() (url.Values, error) { func (c *RequestContext) GetFormValues() (url.Values, error) {
err := c.Req.ParseForm() err := c.Req.ParseForm()
if err != nil { if err != nil {

View File

@ -1,7 +1,6 @@
package website package website
import ( import (
"bytes"
"context" "context"
"errors" "errors"
"fmt" "fmt"
@ -90,6 +89,7 @@ func getBaseData(c *RequestContext) templates.BaseData {
if c.CurrentUser != nil { if c.CurrentUser != nil {
templateUser = &templates.User{ templateUser = &templates.User{
Username: c.CurrentUser.Username, Username: c.CurrentUser.Username,
Name: c.CurrentUser.Name,
Email: c.CurrentUser.Email, Email: c.CurrentUser.Email,
IsSuperuser: c.CurrentUser.IsSuperuser, IsSuperuser: c.CurrentUser.IsSuperuser,
IsStaff: c.CurrentUser.IsStaff, IsStaff: c.CurrentUser.IsStaff,
@ -166,10 +166,17 @@ func ProjectCSS(c *RequestContext) ResponseData {
} }
func FourOhFour(c *RequestContext) ResponseData { func FourOhFour(c *RequestContext) ResponseData {
return ResponseData{ templateData := struct {
StatusCode: http.StatusNotFound, templates.BaseData
Body: bytes.NewBufferString("go away\n"), Wanted string
}{
BaseData: getBaseData(c),
Wanted: c.FullUrl(),
} }
var res ResponseData
res.StatusCode = http.StatusNotFound
res.WriteTemplate("404.html", templateData, c.Perf)
return res
} }
func LoadCommonWebsiteData(c *RequestContext) (bool, ResponseData) { func LoadCommonWebsiteData(c *RequestContext) (bool, ResponseData) {