Skip to content

Commit

Permalink
Fix dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
infogulch committed Jan 27, 2024
1 parent 8aa3758 commit 36b2cbb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ xtemplate*
caddy
Dockerfile
.dockerignore
.gitignore
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ COPY --from=build /build/xtemplate /app/xtemplate
VOLUME /app/data
EXPOSE 80

ENTRYPOINT ["/app/xtemplate", '-template-root', '/app/templates', '-log', '0']
ENTRYPOINT ["/app/xtemplate"]

CMD ["-template-root", "/app/templates", "-watch-template", "false", "-log", "0"]
7 changes: 4 additions & 3 deletions serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (server *xtemplate) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

log := server.log.With(slog.Group("serving",
log := server.log.With(slog.Group("serve",
slog.String("requestid", getRequestId(r.Context())),
slog.String("method", r.Method),
slog.String("path", r.URL.Path),
Expand Down Expand Up @@ -219,7 +219,8 @@ var serveFileHandler http.Handler = http.HandlerFunc(func(w http.ResponseWriter,
}

// if the request provides a hash, check that it matches. if not, we don't have that file
if queryhash := r.URL.Query().Get("hash"); queryhash != "" && queryhash != fileinfo.hash {
queryhash := r.URL.Query().Get("hash")
if queryhash != "" && queryhash != fileinfo.hash {
log.Debug("request for file with wrong hash query parameter", slog.String("expected", fileinfo.hash), slog.String("queryhash", queryhash))
http.NotFound(w, r)
return
Expand Down Expand Up @@ -260,7 +261,7 @@ var serveFileHandler http.Handler = http.HandlerFunc(func(w http.ResponseWriter,
w.Header().Add("Content-Encoding", encoding.encoding)
w.Header().Add("Vary", "Accept-Encoding")
// w.Header().Add("Access-Control-Allow-Origin", "*") // ???
if r.URL.Query().Get("hash") != "" {
if queryhash != "" {
// cache aggressively if the request is disambiguated by a valid hash
// should be `public` ???
w.Header().Set("Cache-Control", "public, max-age=31536000")
Expand Down
4 changes: 4 additions & 0 deletions templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ var instanceIdentity int64
func (configs *config) Build() (CancelHandler, error) {
ctx, cancel := context.WithCancel(context.Background())

// start with default xtemplate struct
x := &xtemplate{
templateFS: os.DirFS("templates"),
ldelim: "{{",
Expand All @@ -74,6 +75,7 @@ func (configs *config) Build() (CancelHandler, error) {
id: atomic.AddInt64(&instanceIdentity, 1),
}

// apply all configs, which are funcs that mutate the xtemplate struct
for _, c := range *configs {
c(x)
}
Expand Down Expand Up @@ -121,6 +123,8 @@ func (configs *config) Build() (CancelHandler, error) {
}
}
}

log.Debug("xtemplate instance initialized", slog.Any("xtemplate", x))
return x, nil
}

Expand Down

0 comments on commit 36b2cbb

Please sign in to comment.