make logging cleaner, etag more
This commit is contained in:
parent
d0ff1b2d04
commit
7e6a1cbd58
|
@ -16,5 +16,5 @@ COPY ./blog /site/blog
|
||||||
COPY ./css /site/css
|
COPY ./css /site/css
|
||||||
COPY ./app /app
|
COPY ./app /app
|
||||||
COPY ./app.json .
|
COPY ./app.json .
|
||||||
HEALTHCHECK CMD wget --spider http://127.0.0.1:5000 || exit 1
|
HEALTHCHECK CMD wget --spider http://127.0.0.1:5000/.within/health || exit 1
|
||||||
CMD ./site
|
CMD ./site
|
||||||
|
|
|
@ -91,6 +91,17 @@ func (s *Site) showPost(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
s.renderTemplatePage("blogpost.html", p).ServeHTTP(w, r)
|
const dateFormat = `2006-01-02`
|
||||||
|
s.renderTemplatePage("blogpost.html", struct {
|
||||||
|
Title string
|
||||||
|
Link string
|
||||||
|
BodyHTML template.HTML
|
||||||
|
Date string
|
||||||
|
}{
|
||||||
|
Title: p.Title,
|
||||||
|
Link: p.Link,
|
||||||
|
BodyHTML: p.BodyHTML,
|
||||||
|
Date: p.Date.Format(dateFormat),
|
||||||
|
}).ServeHTTP(w, r)
|
||||||
postView.With(prometheus.Labels{"base": filepath.Base(p.Link)}).Inc()
|
postView.With(prometheus.Labels{"base": filepath.Base(p.Link)}).Inc()
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"christine.website/internal/blog"
|
"christine.website/internal/blog"
|
||||||
|
@ -38,8 +37,14 @@ func main() {
|
||||||
ln.FatalErr(context.Background(), err, ln.Action("Build"))
|
ln.FatalErr(context.Background(), err, ln.Action("Build"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mux := http.NewServeMux()
|
||||||
|
mux.HandleFunc("/.within/health", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
http.Error(w, "OK", http.StatusOK)
|
||||||
|
})
|
||||||
|
mux.Handle("/", s)
|
||||||
|
|
||||||
ln.Log(context.Background(), ln.F{"action": "http_listening", "port": port})
|
ln.Log(context.Background(), ln.F{"action": "http_listening", "port": port})
|
||||||
http.ListenAndServe(":"+port, s)
|
http.ListenAndServe(":"+port, mux)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Site is the parent object for https://christine.website's backend.
|
// Site is the parent object for https://christine.website's backend.
|
||||||
|
@ -53,9 +58,6 @@ type Site struct {
|
||||||
mux *http.ServeMux
|
mux *http.ServeMux
|
||||||
sitemap []byte
|
sitemap []byte
|
||||||
xffmw *xff.XFF
|
xffmw *xff.XFF
|
||||||
|
|
||||||
templates map[string]*template.Template
|
|
||||||
tlock sync.RWMutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (s *Site) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -169,9 +171,6 @@ func Build() (*Site, error) {
|
||||||
|
|
||||||
s.renderTemplatePage("index.html", nil).ServeHTTP(w, r)
|
s.renderTemplatePage("index.html", nil).ServeHTTP(w, r)
|
||||||
})
|
})
|
||||||
s.mux.HandleFunc("/.within/health", func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
http.Error(w, "OK", http.StatusOK)
|
|
||||||
})
|
|
||||||
s.mux.Handle("/metrics", promhttp.Handler())
|
s.mux.Handle("/metrics", promhttp.Handler())
|
||||||
s.mux.Handle("/resume", middleware.Metrics("resume", s.renderTemplatePage("resume.html", s.Resume)))
|
s.mux.Handle("/resume", middleware.Metrics("resume", s.renderTemplatePage("resume.html", s.Resume)))
|
||||||
s.mux.Handle("/blog", middleware.Metrics("blog", s.renderTemplatePage("blogindex.html", s.Posts)))
|
s.mux.Handle("/blog", middleware.Metrics("blog", s.renderTemplatePage("blogindex.html", s.Posts)))
|
||||||
|
|
|
@ -75,7 +75,6 @@ func (s *Site) createJSONFeed(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
e := json.NewEncoder(w)
|
e := json.NewEncoder(w)
|
||||||
e.SetIndent("", "\t")
|
e.SetIndent("", "\t")
|
||||||
|
|
|
@ -20,7 +20,8 @@ type Post struct {
|
||||||
Summary string `json:"summary,omitifempty"`
|
Summary string `json:"summary,omitifempty"`
|
||||||
Body string `json:"-"`
|
Body string `json:"-"`
|
||||||
BodyHTML template.HTML `json:"body"`
|
BodyHTML template.HTML `json:"body"`
|
||||||
Date time.Time `json:"date"`
|
Date time.Time
|
||||||
|
DateString string `json:"date"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Posts implements sort.Interface for a slice of Post objects.
|
// Posts implements sort.Interface for a slice of Post objects.
|
||||||
|
@ -80,6 +81,7 @@ func LoadPosts(path string) (Posts, error) {
|
||||||
p := Post{
|
p := Post{
|
||||||
Title: fm.Title,
|
Title: fm.Title,
|
||||||
Date: date,
|
Date: date,
|
||||||
|
DateString: fm.Date,
|
||||||
Link: strings.Split(path, ".")[0],
|
Link: strings.Split(path, ".")[0],
|
||||||
Body: string(remaining),
|
Body: string(remaining),
|
||||||
BodyHTML: template.HTML(output),
|
BodyHTML: template.HTML(output),
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
<p>
|
<p>
|
||||||
<ul>
|
<ul>
|
||||||
{{ range . }}
|
{{ range . }}
|
||||||
<li>{{ .Date }} - <a href="{{ .Link }}">{{ .Title }}</a></li>
|
<li>{{ .DateString }} - <a href="{{ .Link }}">{{ .Title }}</a></li>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</ul>
|
</ul>
|
||||||
</p>
|
</p>
|
||||||
|
|
Loading…
Reference in New Issue