mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-13 03:15:48 +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
|
package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"github.com/0xJacky/Nginx-UI/server/api"
|
"github.com/0xJacky/Nginx-UI/server/api"
|
||||||
"github.com/gin-contrib/static"
|
"github.com/gin-contrib/static"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitRouter() *gin.Engine {
|
func InitRouter() *gin.Engine {
|
||||||
|
@ -20,15 +18,7 @@ func InitRouter() *gin.Engine {
|
||||||
r.Use(static.Serve("/", mustFS("")))
|
r.Use(static.Serve("/", mustFS("")))
|
||||||
|
|
||||||
r.NoRoute(func(c *gin.Context) {
|
r.NoRoute(func(c *gin.Context) {
|
||||||
accept := c.Request.Header.Get("Accept")
|
c.Redirect(http.StatusMovedPermanently, "/")
|
||||||
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
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
root := r.Group("/api")
|
root := r.Group("/api")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue