refactor: move DWN proxy server logic to separate file

This commit is contained in:
Prad Nukala
2024-09-25 20:27:00 -04:00
parent 0df3762f13
commit de05777261
8 changed files with 128 additions and 68 deletions
+46
View File
@@ -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)
View File
-24
View File
@@ -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"
]
}
}
}
+30
View File
@@ -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)
}