@@ -3,8 +3,10 @@ package serve
33
44import (
55 "crypto/tls"
6+ "embed"
67 "errors"
78 "fmt"
9+ "io/fs"
810 "net"
911 "net/http"
1012 "net/url"
@@ -13,7 +15,6 @@ import (
1315 "strconv"
1416 "strings"
1517
16- rice "github.com/GeertJohan/go.rice"
1718 "github.com/cloudflare/cfssl/api"
1819 "github.com/cloudflare/cfssl/api/bundle"
1920 "github.com/cloudflare/cfssl/api/certadd"
@@ -81,38 +82,28 @@ func v1APIPath(path string) string {
8182 return (& url.URL {Path : path }).String ()
8283}
8384
84- // httpBox implements http.FileSystem which allows the use of Box with a http.FileServer.
85- // Attempting to Open an API endpoint will result in an error.
86- type httpBox struct {
87- * rice.Box
88- redirects map [string ]string
85+ //go:embed static
86+ var staticContent embed.FS
87+
88+ var staticRedirections = map [string ]string {
89+ "bundle" : "index.html" ,
90+ "scan" : "index.html" ,
91+ "packages" : "index.html" ,
8992}
9093
91- func ( hb * httpBox ) findStaticBox () ( err error ) {
92- hb . Box , err = rice . FindBox ( "static" )
93- return
94+ type staticFS struct {
95+ fs fs. FS
96+ redirections map [ string ] string
9497}
9598
96- // Open returns a File for non-API enpoints using the http.File interface.
97- func (hb * httpBox ) Open (name string ) (http.File , error ) {
99+ func (s * staticFS ) Open (name string ) (fs.File , error ) {
98100 if strings .HasPrefix (name , V1APIPrefix ) {
99101 return nil , os .ErrNotExist
100102 }
101-
102- if location , ok := hb .redirects [name ]; ok {
103- return hb .Box .Open (location )
103+ if location , ok := s .redirections [name ]; ok {
104+ return s .fs .Open (location )
104105 }
105-
106- return hb .Box .Open (name )
107- }
108-
109- // staticBox is the box containing all static assets.
110- var staticBox = & httpBox {
111- redirects : map [string ]string {
112- "/scan" : "/index.html" ,
113- "/bundle" : "/index.html" ,
114- "/packages" : "/index.html" ,
115- },
106+ return s .fs .Open (name )
116107}
117108
118109var errBadSigner = errors .New ("signer not initialized" )
@@ -242,11 +233,8 @@ var endpoints = map[string]func() (http.Handler, error){
242233 },
243234
244235 "/" : func () (http.Handler , error ) {
245- if err := staticBox .findStaticBox (); err != nil {
246- return nil , err
247- }
248-
249- return http .FileServer (staticBox ), nil
236+ subFS , _ := fs .Sub (staticContent , "static" )
237+ return http .FileServer (http .FS (& staticFS {fs : subFS , redirections : staticRedirections })), nil
250238 },
251239
252240 "health" : func () (http.Handler , error ) {
0 commit comments