Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

feat: set install router in release mode. remove install mock router.

LinkinStarb474d3ade30a
diff --git a/internal/install/install_main.go b/internal/install/install_main.go
index a961c280..6586b9d3 100644
--- a/internal/install/install_main.go
+++ b/internal/install/install_main.go
@@ -1,6 +1,7 @@
package install
import (
+ "fmt"
"os"
"github.com/answerdev/answer/internal/base/translator"
@@ -24,6 +25,7 @@ func Run(configPath string) {
if len(port) == 0 {
port = "80"
}
+ fmt.Printf("[SUCCESS] answer installation service will run at: http://localhost:%s/install/ \n", port)
if err = installServer.Run(":" + port); err != nil {
panic(err)
}
diff --git a/internal/install/install_server.go b/internal/install/install_server.go
index a301c197..b2ada51e 100644
--- a/internal/install/install_server.go
+++ b/internal/install/install_server.go
@@ -26,8 +26,8 @@ func (r *_resource) Open(name string) (fs.File, error) {
// NewInstallHTTPServer new install http server.
func NewInstallHTTPServer() *gin.Engine {
+ gin.SetMode(gin.ReleaseMode)
r := gin.New()
- gin.SetMode(gin.DebugMode)
r.GET("/healthz", func(ctx *gin.Context) { ctx.String(200, "OK") })
r.StaticFS("/static", http.FS(&_resource{
fs: ui.Build,
diff --git a/internal/router/ui.go b/internal/router/ui.go
index 84231b0c..3498265c 100644
--- a/internal/router/ui.go
+++ b/internal/router/ui.go
@@ -4,16 +4,11 @@ import (
"embed"
"fmt"
"io/fs"
- "math/rand"
"net/http"
"os"
- "github.com/answerdev/answer/i18n"
- "github.com/answerdev/answer/internal/base/handler"
- "github.com/answerdev/answer/internal/base/translator"
"github.com/answerdev/answer/ui"
"github.com/gin-gonic/gin"
- "github.com/segmentfault/pacman/errors"
"github.com/segmentfault/pacman/log"
)
@@ -45,7 +40,6 @@ func (r *_resource) Open(name string) (fs.File, error) {
// Register a new static resource which generated by ui directory
func (a *UIRouter) Register(r *gin.Engine) {
staticPath := os.Getenv("ANSWER_STATIC_PATH")
- r.StaticFS("/i18n/", http.FS(i18n.I18n))
// if ANSWER_STATIC_PATH is set and not empty, ignore embed resource
if staticPath != "" {
@@ -72,67 +66,6 @@ func (a *UIRouter) Register(r *gin.Engine) {
fs: ui.Build,
}))
- // Install godoc
- // @Summary Install
- // @Description Install
- // @Tags Install
- // @Accept json
- // @Produce json
- // @Success 200 {object} handler.RespBody{}
- // @Router /install [get]
- r.GET("/install", func(c *gin.Context) {
- filePath := ""
- var file []byte
- var err error
- filePath = "build/index.html"
- c.Header("content-type", "text/html;charset=utf-8")
- file, err = ui.Build.ReadFile(filePath)
- if err != nil {
- log.Error(err)
- c.Status(http.StatusNotFound)
- return
- }
- c.String(http.StatusOK, string(file))
- })
-
- r.GET("/installation/language/options", func(c *gin.Context) {
- handler.HandleResponse(c, nil, translator.LanguageOptions)
- })
-
- r.POST("/installation/db/check", func(c *gin.Context) {
- num := rand.Intn(10)
- if num > 5 {
- err := errors.BadRequest("connection error")
- handler.HandleResponse(c, err, gin.H{})
- } else {
- handler.HandleResponse(c, nil, gin.H{
- "connection_success": true,
- })
- }
- })
-
- r.POST("/installation/config-file/check", func(c *gin.Context) {
- num := rand.Intn(10)
- if num > 5 {
- handler.HandleResponse(c, nil, gin.H{
- "exist": true,
- })
- } else {
- handler.HandleResponse(c, nil, gin.H{
- "exist": false,
- })
- }
-
- })
-
- r.POST("/installation/init", func(c *gin.Context) {
- handler.HandleResponse(c, nil, gin.H{})
- })
-
- r.POST("/installation/base-info", func(c *gin.Context) {
- handler.HandleResponse(c, nil, gin.H{})
- })
-
// specify the not router for default routes and redirect
r.NoRoute(func(c *gin.Context) {
name := c.Request.URL.Path