diff --git a/cmd/webserver.go b/cmd/webserver.go index f8796779..ad65f68d 100644 --- a/cmd/webserver.go +++ b/cmd/webserver.go @@ -2,14 +2,12 @@ package cmd import ( "fmt" - "net/http" "path/filepath" "github.com/gin-contrib/gzip" "github.com/gin-gonic/gin" "github.com/gin-gonic/gin/binding" "github.com/go-playground/validator/v10" - "github.com/mssola/user_agent" "github.com/urfave/cli/v2" "github.com/mayswind/ezbookkeeping/pkg/api" @@ -91,19 +89,13 @@ func startWebServer(c *cli.Context) error { router.NoRoute(bindApi(api.Default.ApiNotFound)) router.NoMethod(bindApi(api.Default.MethodNotAllowed)) - router.GET("/", func(c *gin.Context) { - ua := user_agent.New(c.GetHeader("User-Agent")) - - if ua.Mobile() { - c.Redirect(http.StatusMovedPermanently, "/mobile/") - } else { - c.Redirect(http.StatusMovedPermanently, "/desktop/") - } - }) + router.StaticFile("/", filepath.Join(config.StaticRootPath, "index.html")) router.StaticFile("robots.txt", filepath.Join(config.StaticRootPath, "robots.txt")) router.StaticFile("favicon.ico", filepath.Join(config.StaticRootPath, "favicon.ico")) router.StaticFile("favicon.png", filepath.Join(config.StaticRootPath, "favicon.png")) + router.StaticFile("touchicon.png", filepath.Join(config.StaticRootPath, "touchicon.png")) + router.StaticFile("manifest.json", filepath.Join(config.StaticRootPath, "manifest.json")) mobileEntryRoute := router.Group("/mobile") mobileEntryRoute.Use(bindMiddleware(middlewares.ServerSettingsCookie(config))) diff --git a/go.mod b/go.mod index 7f8146d4..94e3706e 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,6 @@ require ( github.com/go-sql-driver/mysql v1.5.0 github.com/lib/pq v1.8.0 github.com/mattn/go-sqlite3 v1.14.4 - github.com/mssola/user_agent v0.5.2 github.com/pquerna/otp v1.3.0 github.com/sirupsen/logrus v1.7.0 github.com/smartystreets/goconvey v1.6.4 // indirect diff --git a/go.sum b/go.sum index 975cfd2b..a6ef9c19 100644 --- a/go.sum +++ b/go.sum @@ -61,8 +61,6 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OH github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/mssola/user_agent v0.5.2 h1:CZkTUahjL1+OcZ5zv3kZr8QiJ8jy2H08vZIEkBeRbxo= -github.com/mssola/user_agent v0.5.2/go.mod h1:TTPno8LPY3wAIEKRpAtkdMT0f8SE24pLRGPahjCH4uw= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= diff --git a/src/Desktop.vue b/src/Desktop.vue index 0fad821f..9648ab2b 100644 --- a/src/Desktop.vue +++ b/src/Desktop.vue @@ -5,7 +5,11 @@ diff --git a/src/index-main.js b/src/index-main.js new file mode 100644 index 00000000..f666fd43 --- /dev/null +++ b/src/index-main.js @@ -0,0 +1,35 @@ +import uaParser from 'ua-parser-js'; + +function isMobileDevice() { + if (!navigator.userAgent) { + return false; + } + + const uaParseRet = uaParser(navigator.userAgent); + + if (!uaParseRet || !uaParseRet.device) { + return false; + } + + const device = uaParseRet.device; + + if (device.type === 'mobile' || device.type === 'tablet' || device.type === 'wearable' || device.type === 'embedded') { + return true; + } + + return false; +} + +function navigate(type) { + if (process.env.NODE_ENV === 'production') { + window.location.replace(`${type}/`); + } else { + window.location.replace(`${type}.html`); + } +} + +if (isMobileDevice()) { + navigate('mobile'); +} else { + navigate('desktop'); +} diff --git a/src/public/index.html b/src/public/index.html new file mode 100644 index 00000000..c5637f6d --- /dev/null +++ b/src/public/index.html @@ -0,0 +1,26 @@ + + +
+ + + + + + + + + + + +