@@ -3,8 +3,10 @@ package terminal
33import (
44 "context"
55 "crypto/tls"
6+ "embed"
67 "errors"
78 "fmt"
9+ "io/fs"
810 "net"
911 "net/http"
1012 "os"
@@ -29,15 +31,10 @@ import (
2931 "github.com/lightningnetwork/lnd/lnrpc"
3032 "github.com/lightningnetwork/lnd/lntest/wait"
3133 "github.com/lightningnetwork/lnd/signal"
32- "github.com/rakyll/statik/fs"
3334 "google.golang.org/grpc"
3435 "google.golang.org/grpc/codes"
3536 "google.golang.org/grpc/status"
3637 "gopkg.in/macaroon-bakery.v2/bakery"
37-
38- // Import generated go package that contains all static files for the
39- // UI in a compressed format.
40- _ "github.com/lightninglabs/lightning-terminal/statik"
4138)
4239
4340const (
5047 // maxMsgRecvSize is the largest message our REST proxy will receive. We
5148 // set this to 200MiB atm.
5249 maxMsgRecvSize = grpc .MaxCallRecvMsgSize (1 * 1024 * 1024 * 200 )
50+
51+ // appBuildFS is an in-memory file system that contains all the static
52+ // HTML/CSS/JS files of the UI. It is compiled into the binary with the
53+ // go 1.16 embed directive below. Because the path is relative to the
54+ // root package, all assets will have a path prefix of /app/build/ which
55+ // we'll strip by giving a sub directory to the HTTP server.
56+ //
57+ //go:embed app/build/*
58+ appBuildFS embed.FS
59+
60+ // appFilesDir is the sub directory of the above build directory which
61+ // we pass to the HTTP server.
62+ appFilesDir = "app/build"
5363)
5464
5565// LightningTerminal is the main grand unified binary instance. Its task is to
@@ -523,14 +533,14 @@ func (g *LightningTerminal) shutdown() error {
523533}
524534
525535// startMainWebServer creates the main web HTTP server that delegates requests
526- // between the Statik HTTP server and the RPC proxy. An incoming request will
536+ // between the embedded HTTP server and the RPC proxy. An incoming request will
527537// go through the following chain of components:
528538//
529539// Request on port 8443
530540// |
531541// v
532542// +---+----------------------+ other +----------------+
533- // | Main web HTTP server +------->+ Statik HTTP |
543+ // | Main web HTTP server +------->+ Embedded HTTP |
534544// +---+----------------------+ +----------------+
535545// |
536546// v any RPC or REST call
@@ -566,12 +576,15 @@ func (g *LightningTerminal) shutdown() error {
566576//
567577func (g * LightningTerminal ) startMainWebServer () error {
568578 // Initialize the in-memory file server from the content compiled by
569- // the statik library.
570- statikFS , err := fs .New ()
579+ // the go:embed directive. Since everything's relative to the root dir,
580+ // we need to create an FS of the sub directory app/build.
581+ buildDir , err := fs .Sub (appBuildFS , appFilesDir )
571582 if err != nil {
572- return fmt . Errorf ( "could not load statik file system: %v" , err )
583+ return err
573584 }
574- staticFileServer := http .FileServer (& ClientRouteWrapper {statikFS })
585+ staticFileServer := http .FileServer (& ClientRouteWrapper {
586+ assets : http .FS (buildDir ),
587+ })
575588
576589 // Both gRPC (web) and static file requests will come into through the
577590 // main UI HTTP server. We use this simple switching handler to send the
0 commit comments