move the function of switching desktop/mobile page to frontend
This commit is contained in:
+3
-11
@@ -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)))
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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=
|
||||
|
||||
+5
-1
@@ -5,7 +5,11 @@
|
||||
<script>
|
||||
export default {
|
||||
created() {
|
||||
location.href = '../mobile/'
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
window.location.replace('../mobile/');
|
||||
} else {
|
||||
window.location.replace('../mobile.html');
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui, viewport-fit=cover">
|
||||
<meta name="mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes"/>
|
||||
<meta name="apple-mobile-web-app-title" content="ezBookkeeping"/>
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="default"/>
|
||||
<meta name="theme-color" content="#c67e48">
|
||||
<meta name="format-detection" content="telephone=no"/>
|
||||
<meta name="description" content="ezBookkeeping is a lightweight personal bookkeeping app hosted by yourself.">
|
||||
<title>ezBookkeeping</title>
|
||||
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
|
||||
<link rel="apple-touch-icon" href="touchicon.png">
|
||||
<link rel="manifest" href="manifest.json">
|
||||
</head>
|
||||
<body>
|
||||
<noscript>
|
||||
<strong>We're sorry but ezBookkeeping doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
|
||||
</noscript>
|
||||
<div id="app"></div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -69,12 +69,6 @@
|
||||
"url": "https://github.com/mattn/go-sqlite3",
|
||||
"licenseUrl": "https://github.com/mattn/go-sqlite3/blob/master/LICENSE"
|
||||
},
|
||||
{
|
||||
"name": "UserAgent",
|
||||
"copyright": "Copyright (c) 2012-2020 Miquel Sabaté Solà",
|
||||
"url": "https://github.com/mssola/user_agent",
|
||||
"licenseUrl": "https://github.com/mssola/user_agent/blob/master/LICENSE"
|
||||
},
|
||||
{
|
||||
"name": "Go Cryptography",
|
||||
"copyright": "Copyright (c) 2009 The Go Authors. All rights reserved.",
|
||||
|
||||
@@ -10,6 +10,12 @@ const licenseFile = fs.readFileSync('./LICENSE', 'UTF-8');
|
||||
|
||||
module.exports = {
|
||||
pages: {
|
||||
index: {
|
||||
entry: 'src/index-main.js',
|
||||
template: 'src/public/index.html',
|
||||
filename: 'index.html',
|
||||
chunks: ['vendors-common-bundle', 'vendors-index-bundle', 'common-bundle', 'index']
|
||||
},
|
||||
desktop: {
|
||||
entry: 'src/desktop-main.js',
|
||||
template: 'src/public/desktop.html',
|
||||
|
||||
Reference in New Issue
Block a user