Skip to content

Commit

Permalink
feat: static html support
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Gianelloni <wolf31o2@blinklabs.io>
  • Loading branch information
wolf31o2 committed Oct 4, 2024
1 parent eb6f420 commit deb6656
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 11 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -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
38 changes: 27 additions & 11 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
package api

import (
"embed"
"fmt"
"io"
"io/fs"
"net/http"
"time"

ouroboros "github.com/blinklabs-io/gouroboros"
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
14 changes: 14 additions & 0 deletions internal/api/static/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>Tx Submit API</title>
</head>
<body>
<p align="center">
<img src="txsubmit-logo.png" />
</p>
<p align="center">
GitHub: <a href="https://github.com/blinklabs-io/tx-submit-api">https://github.com/blinklabs-io/tx-submit-api</a>
</p>
</body>
</html>
Binary file added internal/api/static/txsubmit-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit deb6656

Please sign in to comment.