Skip to content
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
5 changes: 0 additions & 5 deletions cmd/tx-submit-api-mirror/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ func main() {
}

// Start API listener
logger.Infof(
"starting API listener on %s:%d",
cfg.Api.ListenAddress,
cfg.Api.ListenPort,
)
if err := api.Start(cfg); err != nil {
logger.Fatalf("failed to start API: %s", err)
}
Expand Down
32 changes: 27 additions & 5 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ import (
)

func Start(cfg *config.Config) error {
// Standard logging
logger := logging.GetLogger()
if cfg.Tls.CertFilePath != "" && cfg.Tls.KeyFilePath != "" {
logger.Infof(
"starting API TLS listener on %s:%d",
cfg.Api.ListenAddress,
cfg.Api.ListenPort,
)
} else {
logger.Infof(
"starting API listener on %s:%d",
cfg.Api.ListenAddress,
cfg.Api.ListenPort,
)
}
// Disable gin debug output
gin.SetMode(gin.ReleaseMode)
gin.DisableConsoleColor()
Expand All @@ -52,11 +67,18 @@ func Start(cfg *config.Config) error {
router.GET("/healthcheck", handleHealthcheck)
router.POST("/api/submit/tx", handleSubmitTx)

// Start listener
err := router.Run(
fmt.Sprintf("%s:%d", cfg.Api.ListenAddress, cfg.Api.ListenPort),
)
return err
// Start API listener
if cfg.Tls.CertFilePath != "" && cfg.Tls.KeyFilePath != "" {
return router.RunTLS(
fmt.Sprintf("%s:%d", cfg.Api.ListenAddress, cfg.Api.ListenPort),
cfg.Tls.CertFilePath,
cfg.Tls.KeyFilePath,
)
} else {
return router.Run(fmt.Sprintf("%s:%d",
cfg.Api.ListenAddress,
cfg.Api.ListenPort))
}
}

func handleHealthcheck(c *gin.Context) {
Expand Down
6 changes: 6 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
type Config struct {
Logging LoggingConfig `yaml:"logging"`
Api ApiConfig `yaml:"api"`
Tls TlsConfig `yaml:"tls"`
Backends []string `yaml:"backends" envconfig:"BACKENDS"`
}

Expand All @@ -38,6 +39,11 @@ type ApiConfig struct {
ClientTimeout uint `yaml:"client_timeout" envconfig:"CLIENT_TIMEOUT"`
}

type TlsConfig struct {
CertFilePath string `yaml:"certFilePath" envconfig:"TLS_CERT_FILE_PATH"`
KeyFilePath string `yaml:"keyFilePath" envconfig:"TLS_KEY_FILE_PATH"`
}

// Singleton config instance with default values
var globalConfig = &Config{
Logging: LoggingConfig{
Expand Down