@@ -238,15 +238,31 @@ func (g *LightningTerminal) Run() error {
238
238
return fmt .Errorf ("could not create permissions manager" )
239
239
}
240
240
241
+ // Construct the rpcProxy. It must be initialised before the main web
242
+ // server is started.
243
+ g .rpcProxy = newRpcProxy (g .cfg , g , g .validateSuperMacaroon , g .permsMgr )
244
+
245
+ // Start the main web server that dispatches requests either to the
246
+ // static UI file server or the RPC proxy. This makes it possible to
247
+ // unlock lnd through the UI.
248
+ if err := g .startMainWebServer (); err != nil {
249
+ return fmt .Errorf ("error starting main proxy HTTP server: %v" ,
250
+ err )
251
+ }
252
+
253
+ // We'll also create a REST proxy that'll convert any REST calls to gRPC
254
+ // calls and forward them to the internal listener.
255
+ if g .cfg .EnableREST {
256
+ if err := g .createRESTProxy (); err != nil {
257
+ return fmt .Errorf ("error creating REST proxy: %v" , err )
258
+ }
259
+ }
260
+
241
261
// Create the instances of our subservers now so we can hook them up to
242
262
// lnd once it's fully started.
243
- bufRpcListener := bufconn .Listen (100 )
244
263
g .faradayServer = frdrpcserver .NewRPCServer (g .cfg .faradayRpcConfig )
245
264
g .loopServer = loopd .New (g .cfg .Loop , nil )
246
265
g .poolServer = pool .NewServer (g .cfg .Pool )
247
- g .rpcProxy = newRpcProxy (
248
- g .cfg , g , g .validateSuperMacaroon , g .permsMgr ,
249
- )
250
266
g .accountService , err = accounts .NewService (
251
267
filepath .Dir (g .cfg .MacaroonPath ), g .errQueue .ChanIn (),
252
268
)
@@ -345,12 +361,14 @@ func (g *LightningTerminal) Run() error {
345
361
346
362
// Call the "real" main in a nested manner so the defers will properly
347
363
// be executed in the case of a graceful shutdown.
348
- readyChan := make (chan struct {})
349
- bufReadyChan := make (chan struct {})
350
- unlockChan := make (chan struct {})
351
- lndQuit := make (chan struct {})
352
- macChan := make (chan []byte , 1 )
353
-
364
+ var (
365
+ bufRpcListener = bufconn .Listen (100 )
366
+ readyChan = make (chan struct {})
367
+ bufReadyChan = make (chan struct {})
368
+ unlockChan = make (chan struct {})
369
+ lndQuit = make (chan struct {})
370
+ macChan = make (chan []byte , 1 )
371
+ )
354
372
if g .cfg .LndMode == ModeIntegrated {
355
373
lisCfg := lnd.ListenerCfg {
356
374
RPCListeners : []* lnd.ListenerWithSignal {{
@@ -399,14 +417,6 @@ func (g *LightningTerminal) Run() error {
399
417
_ = g .RegisterGrpcSubserver (g .rpcProxy .grpcServer )
400
418
}
401
419
402
- // We'll also create a REST proxy that'll convert any REST calls to gRPC
403
- // calls and forward them to the internal listener.
404
- if g .cfg .EnableREST {
405
- if err := g .createRESTProxy (); err != nil {
406
- return fmt .Errorf ("error creating REST proxy: %v" , err )
407
- }
408
- }
409
-
410
420
// Wait for lnd to be started up so we know we have a TLS cert.
411
421
select {
412
422
// If lnd needs to be unlocked we get the signal that it's ready to do
@@ -444,16 +454,11 @@ func (g *LightningTerminal) Run() error {
444
454
}
445
455
446
456
// Now start the RPC proxy that will handle all incoming gRPC, grpc-web
447
- // and REST requests. We also start the main web server that dispatches
448
- // requests either to the static UI file server or the RPC proxy. This
449
- // makes it possible to unlock lnd through the UI.
457
+ // and REST requests.
450
458
if err := g .rpcProxy .Start (g .lndConn ); err != nil {
451
459
return fmt .Errorf ("error starting lnd gRPC proxy server: %v" ,
452
460
err )
453
461
}
454
- if err := g .startMainWebServer (); err != nil {
455
- return fmt .Errorf ("error starting UI HTTP server: %v" , err )
456
- }
457
462
458
463
// Now that we have started the main UI web server, show some useful
459
464
// information to the user so they can access the web UI easily.
0 commit comments