diff --git a/coderd/coderd.go b/coderd/coderd.go index 8c25c1208bd09..d42e3e931a05b 100644 --- a/coderd/coderd.go +++ b/coderd/coderd.go @@ -334,7 +334,7 @@ func New(options *Options) *API { r.Get("/state", api.workspaceBuildState) }) }) - r.NotFound(site.DefaultHandler().ServeHTTP) + r.NotFound(site.Handler(site.FS()).ServeHTTP) return api } diff --git a/site/embed_slim.go b/site/embed_slim.go deleted file mode 100644 index 489963b994322..0000000000000 --- a/site/embed_slim.go +++ /dev/null @@ -1,12 +0,0 @@ -//go:build !embed -// +build !embed - -package site - -import ( - "net/http" -) - -func DefaultHandler() http.Handler { - return http.NotFoundHandler() -} diff --git a/site/embed.go b/site/site.go similarity index 94% rename from site/embed.go rename to site/site.go index b78ed3a7674c7..25ac15db91339 100644 --- a/site/embed.go +++ b/site/site.go @@ -1,11 +1,7 @@ -//go:build embed -// +build embed - package site import ( "bytes" - "embed" "fmt" "io" "io/fs" @@ -21,26 +17,6 @@ import ( "golang.org/x/xerrors" ) -// The `embed` package ignores recursively including directories -// that prefix with `_`. Wildcarding nested is janky, but seems to -// work quite well for edge-cases. -//go:embed out -//go:embed out/bin/* -var site embed.FS - -func DefaultHandler() http.Handler { - // the out directory is where webpack builds are created. It is in the same - // directory as this file (package site). - siteFS, err := fs.Sub(site, "out") - - if err != nil { - // This can't happen... Go would throw a compilation error. - panic(err) - } - - return Handler(siteFS) -} - // Handler returns an HTTP handler for serving the static site. func Handler(fileSystem fs.FS) http.Handler { // html files are handled by a text/template. Non-html files diff --git a/site/site_embed.go b/site/site_embed.go new file mode 100644 index 0000000000000..f07ddb99441d0 --- /dev/null +++ b/site/site_embed.go @@ -0,0 +1,24 @@ +//go:build embed +// +build embed + +package site + +import ( + "embed" + "io/fs" +) + +//go:embed out +//go:embed out/bin/* +var site embed.FS + +func FS() fs.FS { + // the out directory is where webpack builds are created. It is in the same + // directory as this file (package site). + out, err := fs.Sub(site, "out") + if err != nil { + // This can't happen... Go would throw a compilation error. + panic(err) + } + return out +} diff --git a/site/site_slim.go b/site/site_slim.go new file mode 100644 index 0000000000000..414da032fc26e --- /dev/null +++ b/site/site_slim.go @@ -0,0 +1,15 @@ +//go:build !embed +// +build !embed + +package site + +import ( + "embed" + "io/fs" +) + +var slim embed.FS + +func FS() fs.FS { + return slim +} diff --git a/site/embed_test.go b/site/site_test.go similarity index 99% rename from site/embed_test.go rename to site/site_test.go index 9235f80c898d6..0008d404c66c3 100644 --- a/site/embed_test.go +++ b/site/site_test.go @@ -1,6 +1,3 @@ -//go:build embed -// +build embed - package site_test import (