mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-12 10:55:51 +02:00
enhance: redirect to home if no route #87
This commit is contained in:
parent
445be37f4e
commit
394bd0e578
1 changed files with 85 additions and 95 deletions
|
@ -1,12 +1,10 @@
|
|||
package router
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"github.com/0xJacky/Nginx-UI/server/api"
|
||||
"github.com/gin-contrib/static"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func InitRouter() *gin.Engine {
|
||||
|
@ -20,15 +18,7 @@ func InitRouter() *gin.Engine {
|
|||
r.Use(static.Serve("/", mustFS("")))
|
||||
|
||||
r.NoRoute(func(c *gin.Context) {
|
||||
accept := c.Request.Header.Get("Accept")
|
||||
if strings.Contains(accept, "text/html") {
|
||||
file, _ := mustFS("").Open("index.html")
|
||||
defer file.Close()
|
||||
stat, _ := file.Stat()
|
||||
c.DataFromReader(http.StatusOK, stat.Size(), "text/html",
|
||||
bufio.NewReader(file), nil)
|
||||
return
|
||||
}
|
||||
c.Redirect(http.StatusMovedPermanently, "/")
|
||||
})
|
||||
|
||||
root := r.Group("/api")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue