diff --git a/app/proxy/command.go b/app/proxy/command.go index 60416d160..d025d1f1b 100644 --- a/app/proxy/command.go +++ b/app/proxy/command.go @@ -1,15 +1,8 @@ package proxy import ( - "context" - "net/http" - "os" - "os/signal" - "time" + "log" - "github.com/labstack/echo/v4" - "github.com/labstack/gommon/log" - "github.com/onsonr/sonr/nebula/pages" "github.com/spf13/cobra" ) @@ -17,40 +10,15 @@ func NewProxyCmd() *cobra.Command { return &cobra.Command{ Use: "dwn-proxy", Short: "Starts the DWN proxy server for the local IPFS node", - Run: func(cmd *cobra.Command, args []string) { - // Echo instance - e := echo.New() - e.Logger.SetLevel(log.INFO) - + RunE: func(cmd *cobra.Command, args []string) error { // Load config - _, err := LoadConfig("./") + c, err := LoadConfig(".") if err != nil { - e.Logger.Error(err) - } - - // Configure the server - e.GET("/", pages.Home) - e.GET("/allocate", pages.Profile) - - // Start server - ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt) - defer stop() - // Start server - go func() { - if err := e.Start(":1323"); err != nil && err != http.ErrServerClosed { - e.Logger.Fatal("shutting down the server") - } - }() - - // Wait for interrupt signal to gracefully shutdown the server with a timeout of 10 seconds. - <-ctx.Done() - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) - defer cancel() - - // Shutdown the server with 10 seconds timeout. - if err := e.Shutdown(ctx); err != nil { - e.Logger.Fatal(err) + return err } + log.Printf("Config: %+v", c) + startServer() + return nil }, } } diff --git a/app/proxy/config.go b/app/proxy/config.go index cf906f035..c895f0fa9 100644 --- a/app/proxy/config.go +++ b/app/proxy/config.go @@ -3,11 +3,8 @@ package proxy import "github.com/spf13/viper" type Config struct { - Host string `mapstructure:"HOST"` - Port string `mapstructure:"PORT"` - SSL bool `mapstructure:"SSL"` - CertFile string `mapstructure:"CERT_FILE"` - KeyFile string `mapstructure:"KEY_FILE"` + Host string `mapstructure:"HOST"` + Port string `mapstructure:"PORT"` } func (c *Config) GetHostname() string { diff --git a/app/proxy/server.go b/app/proxy/server.go new file mode 100644 index 000000000..f77afdd96 --- /dev/null +++ b/app/proxy/server.go @@ -0,0 +1,43 @@ +package proxy + +import ( + "context" + "net/http" + "os" + "os/signal" + "time" + + "github.com/labstack/echo/v4" + "github.com/labstack/gommon/log" + "github.com/onsonr/sonr/nebula/pages" +) + +func startServer() { + // Echo instance + e := echo.New() + e.Logger.SetLevel(log.INFO) + + // Configure the server + e.GET("/", pages.Home) + e.GET("/allocate", pages.Profile) + + // Start server + ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt) + defer stop() + // Start server + go func() { + if err := e.Start(":1323"); err != nil && err != http.ErrServerClosed { + e.Logger.Fatal("shutting down the server") + } + }() + + // Wait for interrupt signal to gracefully shutdown the server with a timeout of 10 seconds. + <-ctx.Done() + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + + // Shutdown the server with 10 seconds timeout. + if err := e.Shutdown(ctx); err != nil { + e.Logger.Fatal(err) + } +} diff --git a/nebula/README.md b/nebula/README.md index 52772822e..35a6faa0e 100644 --- a/nebula/README.md +++ b/nebula/README.md @@ -1,3 +1,49 @@ # Nebula A Templ component library for the Sonr DWN (Decentralized Web Node) client. + +## Overview + +### 3rd Party + +- [htmx](https://htmx.org/) +- [tailwindcss](https://tailwindcss.com/) +- [templ](https://templ.dev/) +- [alpinejs](https://alpinejs.dev/) + +### Components + +- Navbar +- Footer +- Login +- Register +- Profile +- Authorize + +## Usage + +```go +package main + +import ( + "github.com/onsonr/sonr/nebula" + "github.com/onsonr/sonr/nebula/components" + "github.com/onsonr/sonr/nebula/pages" +) + +func main() { + e := echo.New() + e.Use(nebula.UseAssets) + e.GET("/", pages.Home) + e.GET("/login", pages.Login) + e.GET("/register", pages.Register) + e.GET("/profile", pages.Profile) + e.GET("/authorize", pages.Authorize) + e.GET("/components", components.Home) + e.Logger.Fatal(e.Start(":1323")) +} +``` + +## License + +[MIT](LICENSE) diff --git a/nebula/assets/js/htmx.min.js b/nebula/assets/js/htmx.min.js new file mode 100644 index 000000000..e69de29bb diff --git a/nebula/devbox.json b/nebula/devbox.json deleted file mode 100644 index 916674a6a..000000000 --- a/nebula/devbox.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "$schema": "https://raw.githubusercontent.com/jetify-com/devbox/0.12.0/.schema/devbox.schema.json", - "packages": [ - "bun@latest" - ], - "env": { - "CLOUDFLARE_API_TOKEN": "$CLOUDFLARE_API_TOKEN", - "GOPATH": "$HOME/go", - "PATH": "$HOME/go/bin:$PATH", - "TEMPL_EXPERIMENT": "rawgo", - "CHAIN_ID": "sonr-testnet-1", - "DENOM": "usnr", - "KEYRING": "test", - "MONIKER": "florence", - "ENV": "$ENVIRONMENT" - }, - "shell": { - "scripts": { - "build": [ - "make build" - ] - } - } -} diff --git a/nebula/nebula.go b/nebula/nebula.go index 2808317c2..bcfa90b97 100644 --- a/nebula/nebula.go +++ b/nebula/nebula.go @@ -1 +1,31 @@ package nebula + +import ( + "embed" + "io/fs" + "net/http" + "os" + + "github.com/labstack/echo/v4" +) + +//go:embed assets +var embeddedFiles embed.FS + +func getFileSystem(useOS bool) http.FileSystem { + if useOS { + return http.FS(os.DirFS("assets")) + } + + fsys, err := fs.Sub(embeddedFiles, "assets") + if err != nil { + panic(err) + } + + return http.FS(fsys) +} + +func UseAssets(e *echo.Echo) echo.HandlerFunc { + assets := http.FileServer(getFileSystem(true)) + return echo.WrapHandler(assets) +} diff --git a/x/vault/internal/app.wasm b/x/vault/internal/app.wasm index 97f76e149..09f3eb496 100755 Binary files a/x/vault/internal/app.wasm and b/x/vault/internal/app.wasm differ