package router

import (
	"net/http"
	"strings"

	"github.com/gin-gonic/gin"
)

func frontendStaticRouter(router *gin.Engine) {
	router.Static("./static", "../web/ismp-automation-web/static")
	router.StaticFile("./", "../web/ismp-automation-web/index.html")

	// 解决页面刷新404的问题
	router.NoRoute(func(c *gin.Context) {
		uri := c.Request.RequestURI

		// Swagger 放行
		if strings.HasPrefix(uri, "/swagger") {
			c.AbortWithStatus(http.StatusNotFound)
			return
		}

		if !strings.HasPrefix(uri, "/automation/boltdog/openapi/v2") {
			c.File("../web/ismp-automation-web/index.html")
			return
		}
		c.AbortWithStatus(http.StatusNotFound)
	})
}