|
@@ -5,7 +5,9 @@ import (
|
|
|
"auto-ssl/handlers"
|
|
"auto-ssl/handlers"
|
|
|
"auto-ssl/services"
|
|
"auto-ssl/services"
|
|
|
"log"
|
|
"log"
|
|
|
|
|
+ "net/http"
|
|
|
"os"
|
|
"os"
|
|
|
|
|
+ "strings"
|
|
|
"time"
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/gin-contrib/cors"
|
|
"github.com/gin-contrib/cors"
|
|
@@ -57,6 +59,17 @@ func main() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
r.NoRoute(func(c *gin.Context) {
|
|
r.NoRoute(func(c *gin.Context) {
|
|
|
|
|
+ // 静态资源请求直接返回404,避免返回html导致MIME类型错误
|
|
|
|
|
+ if strings.HasPrefix(c.Request.URL.Path, "/assets/") ||
|
|
|
|
|
+ strings.HasSuffix(c.Request.URL.Path, ".js") ||
|
|
|
|
|
+ strings.HasSuffix(c.Request.URL.Path, ".css") ||
|
|
|
|
|
+ strings.HasSuffix(c.Request.URL.Path, ".png") ||
|
|
|
|
|
+ strings.HasSuffix(c.Request.URL.Path, ".svg") ||
|
|
|
|
|
+ strings.HasSuffix(c.Request.URL.Path, ".ico") {
|
|
|
|
|
+ c.AbortWithStatus(http.StatusNotFound)
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ // 其他路由返回index.html给前端处理
|
|
|
c.File("./dist/index.html")
|
|
c.File("./dist/index.html")
|
|
|
})
|
|
})
|
|
|
|
|
|