diff --git a/CODEOWNERS b/CODEOWNERS index 7e28784..745ce55 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -2,4 +2,5 @@ # * @blinklabs-io/core *.md @blinklabs-io/core @blinklabs-io/pms +internal/api/static/* @blinklabs-io/core @blinklabs-io/frontend LICENSE @blinklabs-io/core @blinklabs-io/pms diff --git a/internal/api/api.go b/internal/api/api.go index 5a377c4..39da78d 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -15,8 +15,11 @@ package api import ( + "embed" "fmt" "io" + "io/fs" + "net/http" "time" ouroboros "github.com/blinklabs-io/gouroboros" @@ -34,16 +37,18 @@ import ( "github.com/blinklabs-io/tx-submit-api/submit" ) -// @title tx-submit-api -// @version v0 -// @description Cardano Transaction Submit API -// @Schemes http -// @BasePath / - -// @contact.name Blink Labs -// @contact.url https://blinklabs.io -// @contact.email support@blinklabs.io +//go:embed static +var staticFS embed.FS +// @title tx-submit-api +// @version v0 +// @description Cardano Transaction Submit API +// @Schemes http +// @BasePath / +// @contact.name Blink Labs +// @contact.url https://blinklabs.io +// @contact.email support@blinklabs.io +// // @license.name Apache 2.0 // @license.url http://www.apache.org/licenses/LICENSE-2.0.html func Start(cfg *config.Config) error { @@ -71,6 +76,18 @@ func Start(cfg *config.Config) error { })) router.Use(ginzap.RecoveryWithZap(accessLogger, true)) + // Configure static route + fsys, err := fs.Sub(staticFS, "static") + if err != nil { + return err + } + router.StaticFS("/ui", http.FS(fsys)) + // Redirect from root + router.GET("/", func(c *gin.Context) { + c.Request.URL.Path = "/ui" + router.HandleContext(c) + }) + // Create a healthcheck (before metrics so it's not instrumented) router.GET("/healthcheck", handleHealthcheck) // Create a swagger endpoint (not instrumented) @@ -121,10 +138,9 @@ func Start(cfg *config.Config) error { router.GET("/api/hastx/:tx_hash", handleHasTx) // Start API listener - err := router.Run(fmt.Sprintf("%s:%d", + return router.Run(fmt.Sprintf("%s:%d", cfg.Api.ListenAddress, cfg.Api.ListenPort)) - return err } func handleHealthcheck(c *gin.Context) { diff --git a/internal/api/static/index.html b/internal/api/static/index.html new file mode 100644 index 0000000..f1b0a85 --- /dev/null +++ b/internal/api/static/index.html @@ -0,0 +1,14 @@ + + + +Tx Submit API + + +

+ +

+

+GitHub: https://github.com/blinklabs-io/tx-submit-api +

+ + diff --git a/internal/api/static/txsubmit-logo.png b/internal/api/static/txsubmit-logo.png new file mode 100644 index 0000000..40b76d8 Binary files /dev/null and b/internal/api/static/txsubmit-logo.png differ