Skip to content

Commit 19580a7

Browse files
committed
Fix swagger favicon
1 parent 9592ad2 commit 19580a7

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

api/main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"fmt"
55
"os"
6+
"strings"
67

78
"github.com/NdoleStudio/httpsms/docs"
89
"github.com/NdoleStudio/httpsms/pkg/di"
@@ -33,7 +34,12 @@ func main() {
3334
di.LoadEnv()
3435
}
3536

36-
docs.SwaggerInfo.Host = os.Getenv("SWAGGER_HOST")
37+
if host := strings.TrimSpace(os.Getenv("SWAGGER_HOST")); len(host) > 0 {
38+
docs.SwaggerInfo.Host = host
39+
}
40+
if len(Version) > 0 {
41+
docs.SwaggerInfo.Version = Version
42+
}
3743

3844
container := di.NewContainer("http-sms", Version)
3945
container.Logger().Info(container.App().Listen(fmt.Sprintf("%s:%s", os.Getenv("APP_HOST"), os.Getenv("APP_PORT"))).Error())

api/pkg/di/container.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"strconv"
1010
"time"
1111

12+
"github.com/NdoleStudio/httpsms/docs"
13+
1214
otelMetric "go.opentelemetry.io/otel/metric"
1315

1416
"github.com/dgraph-io/ristretto"
@@ -1344,7 +1346,16 @@ func (container *Container) RegisterEventRoutes() {
13441346
// RegisterSwaggerRoutes registers routes for swagger
13451347
func (container *Container) RegisterSwaggerRoutes() {
13461348
container.logger.Debug(fmt.Sprintf("registering %T routes", swagger.HandlerDefault))
1347-
container.App().Get("/*", swagger.HandlerDefault)
1349+
container.App().Get("/*", swagger.New(swagger.Config{
1350+
Title: docs.SwaggerInfo.Title,
1351+
CustomScript: `
1352+
document.addEventListener("DOMContentLoaded", function(event) {
1353+
var links = document.querySelectorAll("link[rel~='icon']");
1354+
links.forEach(function (link) {
1355+
link.href = 'https://httpsms.com/favicon.ico';
1356+
});
1357+
});`,
1358+
}))
13481359
}
13491360

13501361
// HeartbeatRepository registers a new instance of repositories.HeartbeatRepository

0 commit comments

Comments
 (0)