github.com/pojntfx/hydrapp/hydrapp@v0.0.0-20240516002902-d08759d6ca9f/pkg/generators/main_vanillajs_rest.go.tpl (about) 1 //go:build !android 2 // +build !android 3 4 package main 5 6 import ( 7 "bytes" 8 "context" 9 _ "embed" 10 "log" 11 "os" 12 13 "{{ .GoMod }}/pkg/backend" 14 "{{ .GoMod }}/pkg/frontend" 15 "github.com/pojntfx/hydrapp/hydrapp/pkg/browser" 16 "github.com/pojntfx/hydrapp/hydrapp/pkg/config" 17 _ "github.com/pojntfx/hydrapp/hydrapp/pkg/fixes" 18 "github.com/pojntfx/hydrapp/hydrapp/pkg/update" 19 "github.com/pojntfx/hydrapp/hydrapp/pkg/utils" 20 ) 21 22 //go:embed hydrapp.yaml 23 var configFile []byte 24 25 func main() { 26 ctx, cancel := context.WithCancel(context.Background()) 27 defer cancel() 28 29 cfg, err := config.Parse(bytes.NewBuffer(configFile)) 30 if err != nil { 31 utils.HandlePanic("App", "could not parse config file", err) 32 33 return 34 } 35 36 // Apply the self-update 37 browserState := &update.BrowserState{} 38 go update.Update( 39 ctx, 40 41 cfg, 42 browserState, 43 utils.HandlePanic, 44 ) 45 46 // Start the backend 47 backendURL, stopBackend, err := backend.StartServer(ctx, os.Getenv(utils.EnvBackendLaddr), true) 48 if err != nil { 49 utils.HandlePanic(cfg.App.Name, "could not start backend", err) 50 } 51 defer stopBackend() 52 53 log.Println("Backend URL:", backendURL) 54 55 // Start the frontend 56 frontendURL, stopFrontend, err := frontend.StartServer(ctx, os.Getenv(utils.EnvFrontendLaddr), backendURL, true) 57 if err != nil { 58 utils.HandlePanic(cfg.App.Name, "could not start frontend", err) 59 } 60 defer stopFrontend() 61 62 log.Println("Frontend URL:", frontendURL) 63 64 browser.LaunchBrowser( 65 frontendURL, 66 cfg.App.Name, 67 cfg.App.ID, 68 69 os.Getenv(utils.EnvBrowser), 70 os.Getenv(utils.EnvType), 71 72 browser.ChromiumLikeBrowsers, 73 browser.FirefoxLikeBrowsers, 74 browser.EpiphanyLikeBrowsers, 75 browser.LynxLikeBrowsers, 76 77 browserState, 78 func(msg string, err error) { 79 utils.HandlePanic(cfg.App.Name, msg, err) 80 }, 81 ) 82 }