liuxiaolong
2019-08-16 cfeba2dea02c1de54cde6c95f2a3f46c121d34aa
dev add publicDomain
3个文件已修改
14 ■■■■■ 已修改文件
config/dev.yaml 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
extend/config/config.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
middlewares/auth/auth.go 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
config/dev.yaml
@@ -4,6 +4,7 @@
    jwtExpire: 24  
    url: http://127.0.0.1:8080
    imageUrl: http://192.168.1.203:6080
    publicDomain: bsic.asuscomm.com
    networkAdapter: enp8s0
compare:
    url:
extend/config/config.go
@@ -12,6 +12,7 @@
    JwtExpire string `mapstructure: "jwtExpire"`
    Url       string `mapstructure: "url"`
    ImageUrl  string `mapstructure: "imageUrl"`
    PublicDomain string `mapstructure: "publicDomain"`
    NetworkAdapter string `mapstructure: "networkAdapter"`
}
middlewares/auth/auth.go
@@ -3,6 +3,7 @@
import (
    "github.com/gin-gonic/gin"
    "net/http"
    "regexp"
    "strings"
    "webserver/extend/config"
    "webserver/extend/logger"
@@ -28,6 +29,7 @@
func AuthHandler() gin.HandlerFunc {
    return func(c *gin.Context) {
        urlPath := c.Request.URL.Path
        if strings.Contains(urlPath,"/data/api-v") && !strings.Contains(urlPath,"login"){
            //jwtDriver :=NewJwtAuthDriver()
            //if !jwtDriver.Check(c) {
@@ -36,7 +38,17 @@
            //}
            c.Next()
        } else if strings.HasPrefix(urlPath,"/httpImage") {
            host := c.Request.Host
            logger.Debug("host:", host)
            imgUrl := config.Server.ImageUrl
            domain := config.Server.PublicDomain
            domainReg := regexp.MustCompile(``+domain+``)
            if domainReg.MatchString(host) {//域名访问
                imgUrl = domain
            }
            urlPath = strings.Replace(urlPath, "/httpImage", "", -1)
            idx := strings.Index(urlPath, ":")
            tmpPath := urlPath