1515package api
1616
1717import (
18+ "embed"
1819 "fmt"
1920 "io"
21+ "io/fs"
22+ "net/http"
2023 "time"
2124
2225 ouroboros "github.com/blinklabs-io/gouroboros"
@@ -34,16 +37,18 @@ import (
3437 "github.com/blinklabs-io/tx-submit-api/submit"
3538)
3639
37- // @title tx-submit-api
38- // @version v0
39- // @description Cardano Transaction Submit API
40- // @Schemes http
41- // @BasePath /
42-
43- // @contact.name Blink Labs
44- // @contact.url https://blinklabs.io
45- // @contact.email [email protected] 40+ //go:embed static
41+ var staticFS embed.FS
4642
43+ // @title tx-submit-api
44+ // @version v0
45+ // @description Cardano Transaction Submit API
46+ // @Schemes http
47+ // @BasePath /
48+ // @contact.name Blink Labs
49+ // @contact.url https://blinklabs.io
50+ // @contact.email [email protected] 51+ //
4752// @license.name Apache 2.0
4853// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
4954func Start (cfg * config.Config ) error {
@@ -71,6 +76,18 @@ func Start(cfg *config.Config) error {
7176 }))
7277 router .Use (ginzap .RecoveryWithZap (accessLogger , true ))
7378
79+ // Configure static route
80+ fsys , err := fs .Sub (staticFS , "static" )
81+ if err != nil {
82+ return err
83+ }
84+ router .StaticFS ("/ui" , http .FS (fsys ))
85+ // Redirect from root
86+ router .GET ("/" , func (c * gin.Context ) {
87+ c .Request .URL .Path = "/ui"
88+ router .HandleContext (c )
89+ })
90+
7491 // Create a healthcheck (before metrics so it's not instrumented)
7592 router .GET ("/healthcheck" , handleHealthcheck )
7693 // Create a swagger endpoint (not instrumented)
@@ -121,10 +138,9 @@ func Start(cfg *config.Config) error {
121138 router .GET ("/api/hastx/:tx_hash" , handleHasTx )
122139
123140 // Start API listener
124- err := router .Run (fmt .Sprintf ("%s:%d" ,
141+ return router .Run (fmt .Sprintf ("%s:%d" ,
125142 cfg .Api .ListenAddress ,
126143 cfg .Api .ListenPort ))
127- return err
128144}
129145
130146func handleHealthcheck (c * gin.Context ) {
0 commit comments