Skip to content

Commit

Permalink
api: rest: Change API URL and add redirect URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
ish-hcc committed Jul 4, 2024
1 parent 8753da8 commit 3d342ca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion pkg/api/rest/route/swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@ import (
"github.com/cloud-barista/cm-grasshopper/common"
"github.com/labstack/echo/v4"
echoSwagger "github.com/swaggo/echo-swagger"
"net/http"
"strings"
)

func RegisterSwagger(e *echo.Echo) {
e.GET("/"+strings.ToLower(common.ShortModuleName)+"/swagger/*", echoSwagger.WrapHandler)
swaggerRedirect := func(c echo.Context) error {
return c.Redirect(http.StatusMovedPermanently, "/"+strings.ToLower(common.ShortModuleName)+"/api/index.html")
}
e.GET("", swaggerRedirect)
e.GET("/", swaggerRedirect)
e.GET("/"+strings.ToLower(common.ShortModuleName), swaggerRedirect)
e.GET("/"+strings.ToLower(common.ShortModuleName)+"/", swaggerRedirect)
e.GET("/"+strings.ToLower(common.ShortModuleName)+"/api", swaggerRedirect)
e.GET("/"+strings.ToLower(common.ShortModuleName)+"/api/", swaggerRedirect)
e.GET("/"+strings.ToLower(common.ShortModuleName)+"/api/*", echoSwagger.WrapHandler)
}
2 changes: 1 addition & 1 deletion pkg/api/rest/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func Init() {

// Display API Docs Dashboard when server starts
endpoint := getLocalIP() + ":" + config.CMGrasshopperConfig.CMGrasshopper.Listen.Port
apiDocsDashboard := " http://" + endpoint + "/" + strings.ToLower(common.ShortModuleName) + "/swagger/index.html"
apiDocsDashboard := " http://" + endpoint + "/" + strings.ToLower(common.ShortModuleName) + "/api/index.html"

fmt.Println("\n ")
fmt.Println(" CM-Grasshopper repository:")
Expand Down

0 comments on commit 3d342ca

Please sign in to comment.