Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: static html support #243

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.