Skip to content

Send and receive SMS messages using your Android phone programmatically via a simple HTTP API

Fix swagger favicon

Acho Arnold19580a73ecf8
diff --git a/api/main.go b/api/main.go
index 36c5da61..a208459c 100644
--- a/api/main.go
+++ b/api/main.go
@@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
+ "strings"
"github.com/NdoleStudio/httpsms/docs"
"github.com/NdoleStudio/httpsms/pkg/di"
@@ -33,7 +34,12 @@ func main() {
di.LoadEnv()
}
- docs.SwaggerInfo.Host = os.Getenv("SWAGGER_HOST")
+ if host := strings.TrimSpace(os.Getenv("SWAGGER_HOST")); len(host) > 0 {
+ docs.SwaggerInfo.Host = host
+ }
+ if len(Version) > 0 {
+ docs.SwaggerInfo.Version = Version
+ }
container := di.NewContainer("http-sms", Version)
container.Logger().Info(container.App().Listen(fmt.Sprintf("%s:%s", os.Getenv("APP_HOST"), os.Getenv("APP_PORT"))).Error())
diff --git a/api/pkg/di/container.go b/api/pkg/di/container.go
index 64025dcc..6b54f63b 100644
--- a/api/pkg/di/container.go
+++ b/api/pkg/di/container.go
@@ -9,6 +9,8 @@ import (
"strconv"
"time"
+ "github.com/NdoleStudio/httpsms/docs"
+
otelMetric "go.opentelemetry.io/otel/metric"
"github.com/dgraph-io/ristretto"
@@ -1344,7 +1346,16 @@ func (container *Container) RegisterEventRoutes() {
// RegisterSwaggerRoutes registers routes for swagger
func (container *Container) RegisterSwaggerRoutes() {
container.logger.Debug(fmt.Sprintf("registering %T routes", swagger.HandlerDefault))
- container.App().Get("/*", swagger.HandlerDefault)
+ container.App().Get("/*", swagger.New(swagger.Config{
+ Title: docs.SwaggerInfo.Title,
+ CustomScript: `
+ document.addEventListener("DOMContentLoaded", function(event) {
+ var links = document.querySelectorAll("link[rel~='icon']");
+ links.forEach(function (link) {
+ link.href = 'https://httpsms.com/favicon.ico';
+ });
+ });`,
+ }))
}
// HeartbeatRepository registers a new instance of repositories.HeartbeatRepository