@@ -3,8 +3,10 @@ package serve
3
3
4
4
import (
5
5
"crypto/tls"
6
+ "embed"
6
7
"errors"
7
8
"fmt"
9
+ "io/fs"
8
10
"net"
9
11
"net/http"
10
12
"net/url"
@@ -13,7 +15,6 @@ import (
13
15
"strconv"
14
16
"strings"
15
17
16
- rice "github.com/GeertJohan/go.rice"
17
18
"github.com/cloudflare/cfssl/api"
18
19
"github.com/cloudflare/cfssl/api/bundle"
19
20
"github.com/cloudflare/cfssl/api/certadd"
@@ -81,38 +82,28 @@ func v1APIPath(path string) string {
81
82
return (& url.URL {Path : path }).String ()
82
83
}
83
84
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" ,
89
92
}
90
93
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
94
97
}
95
98
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 ) {
98
100
if strings .HasPrefix (name , V1APIPrefix ) {
99
101
return nil , os .ErrNotExist
100
102
}
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 )
104
105
}
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 )
116
107
}
117
108
118
109
var errBadSigner = errors .New ("signer not initialized" )
@@ -242,11 +233,8 @@ var endpoints = map[string]func() (http.Handler, error){
242
233
},
243
234
244
235
"/" : 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
250
238
},
251
239
252
240
"health" : func () (http.Handler , error ) {
0 commit comments