修复跨端问题
This commit is contained in:
@@ -178,11 +178,19 @@ func defaultWebSocketPath() string {
|
|||||||
|
|
||||||
func defaultWebSocketPathForGOOS(goos string) string {
|
func defaultWebSocketPathForGOOS(goos string) string {
|
||||||
if goos == "windows" {
|
if goos == "windows" {
|
||||||
return filepath.Join(".", "win", "opt", "mesh_mqtt_go", "web.sock")
|
return ""
|
||||||
}
|
}
|
||||||
return filepath.Join(string(filepath.Separator), "opt", "mesh_mqtt_go", "web.sock")
|
return filepath.Join(string(filepath.Separator), "opt", "mesh_mqtt_go", "web.sock")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func clearWebSocketPathOnUnsupportedGOOS(cfg *config, goos string) bool {
|
||||||
|
if goos != "windows" || cfg.Web.SocketPath == "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
cfg.Web.SocketPath = ""
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func defaultSQLitePathForGOOS(goos string) string {
|
func defaultSQLitePathForGOOS(goos string) string {
|
||||||
if goos == "windows" {
|
if goos == "windows" {
|
||||||
return filepath.Join(".", "win", "etc", "mesh_mqtt_go", "mesh_mqtt_go.db")
|
return filepath.Join(".", "win", "etc", "mesh_mqtt_go", "mesh_mqtt_go.db")
|
||||||
@@ -221,6 +229,9 @@ func loadConfig(path string) (*config, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cfg, changed := normalizeConfig(raw)
|
cfg, changed := normalizeConfig(raw)
|
||||||
|
if clearWebSocketPathOnUnsupportedGOOS(cfg, runtime.GOOS) {
|
||||||
|
changed = true
|
||||||
|
}
|
||||||
if err := validateConfig(cfg); err != nil {
|
if err := validateConfig(cfg); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -154,6 +154,37 @@ func TestLoadConfigMalformedYAMLDoesNotOverwrite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDefaultWebSocketPathForGOOS(t *testing.T) {
|
||||||
|
if windowsPath := defaultWebSocketPathForGOOS("windows"); windowsPath != "" {
|
||||||
|
t.Fatalf("windows web socket path = %q, want empty", windowsPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
linuxPath := defaultWebSocketPathForGOOS("linux")
|
||||||
|
want := filepath.Join(string(filepath.Separator), "opt", "mesh_mqtt_go", "web.sock")
|
||||||
|
if linuxPath != want {
|
||||||
|
t.Fatalf("linux web socket path = %q, want %q", linuxPath, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestClearWebSocketPathOnUnsupportedGOOS(t *testing.T) {
|
||||||
|
cfg := defaultConfig()
|
||||||
|
cfg.Web.SocketPath = filepath.Join(".", "win", "opt", "mesh_mqtt_go", "web.sock")
|
||||||
|
if !clearWebSocketPathOnUnsupportedGOOS(cfg, "windows") {
|
||||||
|
t.Fatalf("clearWebSocketPathOnUnsupportedGOOS() = false, want true")
|
||||||
|
}
|
||||||
|
if cfg.Web.SocketPath != "" {
|
||||||
|
t.Fatalf("windows web socket path = %q, want empty", cfg.Web.SocketPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg.Web.SocketPath = "/opt/mesh_mqtt_go/web.sock"
|
||||||
|
if clearWebSocketPathOnUnsupportedGOOS(cfg, "linux") {
|
||||||
|
t.Fatalf("linux clearWebSocketPathOnUnsupportedGOOS() = true, want false")
|
||||||
|
}
|
||||||
|
if cfg.Web.SocketPath == "" {
|
||||||
|
t.Fatalf("linux web socket path was cleared")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestDefaultSQLitePathForGOOS(t *testing.T) {
|
func TestDefaultSQLitePathForGOOS(t *testing.T) {
|
||||||
windowsPath := defaultSQLitePathForGOOS("windows")
|
windowsPath := defaultSQLitePathForGOOS("windows")
|
||||||
if !strings.Contains(windowsPath, filepath.Join("win", "etc", "mesh_mqtt_go", "mesh_mqtt_go.db")) {
|
if !strings.Contains(windowsPath, filepath.Join("win", "etc", "mesh_mqtt_go", "mesh_mqtt_go.db")) {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
@@ -214,7 +215,7 @@ func parseArgs() (*config, error) {
|
|||||||
flag.BoolVar(&cfg.Web.Enabled, "web", cfg.Web.Enabled, "Enable Gin web server")
|
flag.BoolVar(&cfg.Web.Enabled, "web", cfg.Web.Enabled, "Enable Gin web server")
|
||||||
flag.StringVar(&cfg.Web.Host, "web-host", cfg.Web.Host, "Web server listen host")
|
flag.StringVar(&cfg.Web.Host, "web-host", cfg.Web.Host, "Web server listen host")
|
||||||
flag.IntVar(&cfg.Web.Port, "web-port", cfg.Web.Port, "Web server listen port")
|
flag.IntVar(&cfg.Web.Port, "web-port", cfg.Web.Port, "Web server listen port")
|
||||||
flag.StringVar(&cfg.Web.SocketPath, "web-socket-path", cfg.Web.SocketPath, "Web server Unix socket path; empty uses host and port")
|
flag.StringVar(&cfg.Web.SocketPath, "web-socket-path", cfg.Web.SocketPath, "Web server Unix socket path; empty uses host and port; unsupported on Windows")
|
||||||
flag.StringVar(&cfg.Web.StaticDir, "web-static-dir", cfg.Web.StaticDir, "Web frontend static files directory")
|
flag.StringVar(&cfg.Web.StaticDir, "web-static-dir", cfg.Web.StaticDir, "Web frontend static files directory")
|
||||||
flag.StringVar(&cfg.Web.Admin.Username, "admin-username", cfg.Web.Admin.Username, "Web admin username")
|
flag.StringVar(&cfg.Web.Admin.Username, "admin-username", cfg.Web.Admin.Username, "Web admin username")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
@@ -225,6 +226,7 @@ func parseArgs() (*config, error) {
|
|||||||
if value := os.Getenv("MESH_ADMIN_SESSION_SECRET"); value != "" {
|
if value := os.Getenv("MESH_ADMIN_SESSION_SECRET"); value != "" {
|
||||||
cfg.Web.Admin.SessionSecret = value
|
cfg.Web.Admin.SessionSecret = value
|
||||||
}
|
}
|
||||||
|
clearWebSocketPathOnUnsupportedGOOS(cfg, runtime.GOOS)
|
||||||
|
|
||||||
if err := validateConfig(cfg); err != nil {
|
if err := validateConfig(cfg); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ let markerLayer: L.LayerGroup | null = null
|
|||||||
let hasFitBounds = false
|
let hasFitBounds = false
|
||||||
|
|
||||||
const minMapZoom = 3
|
const minMapZoom = 3
|
||||||
|
const defaultMapCenter: L.LatLngExpression = [35.8617, 104.1954]
|
||||||
|
const defaultMapZoom = 4
|
||||||
const worldBounds = L.latLngBounds(
|
const worldBounds = L.latLngBounds(
|
||||||
[-85.05112878, -180],
|
[-85.05112878, -180],
|
||||||
[85.05112878, 180],
|
[85.05112878, 180],
|
||||||
@@ -50,7 +52,7 @@ onMounted(async () => {
|
|||||||
maxBounds: worldBounds,
|
maxBounds: worldBounds,
|
||||||
maxBoundsViscosity: 1.0,
|
maxBoundsViscosity: 1.0,
|
||||||
worldCopyJump: false,
|
worldCopyJump: false,
|
||||||
}).setView([0, 0], minMapZoom)
|
}).setView(defaultMapCenter, defaultMapZoom)
|
||||||
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||||
minZoom: minMapZoom,
|
minZoom: minMapZoom,
|
||||||
maxZoom: 19,
|
maxZoom: 19,
|
||||||
|
|||||||
Reference in New Issue
Block a user