Skip to content

Commit 541501d

Browse files
authored
feat: static html support (#243)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent dda2495 commit 541501d

File tree

4 files changed

+42
-11
lines changed

4 files changed

+42
-11
lines changed

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
#
33
* @blinklabs-io/core
44
*.md @blinklabs-io/core @blinklabs-io/pms
5+
internal/api/static/* @blinklabs-io/core @blinklabs-io/frontend
56
LICENSE @blinklabs-io/core @blinklabs-io/pms

internal/api/api.go

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
package api
1616

1717
import (
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
4954
func 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

130146
func handleHealthcheck(c *gin.Context) {

internal/api/static/index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Tx Submit API</title>
5+
</head>
6+
<body>
7+
<p align="center">
8+
<img src="txsubmit-logo.png" />
9+
</p>
10+
<p align="center">
11+
GitHub: <a href="https://github.com/blinklabs-io/tx-submit-api">https://github.com/blinklabs-io/tx-submit-api</a>
12+
</p>
13+
</body>
14+
</html>
25 KB
Loading

0 commit comments

Comments
 (0)