ai-gateway/router/main.go

26 lines
594 B
Go
Raw Normal View History

2023-04-22 12:39:27 +00:00
package router
import (
"embed"
"fmt"
2023-04-22 12:39:27 +00:00
"github.com/gin-gonic/gin"
"net/http"
"os"
"strings"
2023-04-22 12:39:27 +00:00
)
func SetRouter(router *gin.Engine, buildFS embed.FS, indexPage []byte) {
SetApiRouter(router)
SetDashboardRouter(router)
2023-04-23 10:24:11 +00:00
SetRelayRouter(router)
frontendBaseUrl := os.Getenv("FRONTEND_BASE_URL")
if frontendBaseUrl == "" {
SetWebRouter(router, buildFS, indexPage)
} else {
frontendBaseUrl = strings.TrimSuffix(frontendBaseUrl, "/")
router.NoRoute(func(c *gin.Context) {
c.Redirect(http.StatusMovedPermanently, fmt.Sprintf("%s%s", frontendBaseUrl, c.Request.RequestURI))
})
}
2023-04-22 12:39:27 +00:00
}