Compare commits

...

4 Commits

Author SHA1 Message Date
MrFastwind
914e0fbe48 Make deployment-friendly defaults: no env vars needed to run
Some checks failed
CI / build (push) Failing after 3s
- Go binary defaults DATA_DIR=./data, SERVERFILE_DIR=./serverfiles
  (relative to cwd) — just copy the binary and run
- MODS_DIR, CFG_DIR, PROFILES_DIR are derived from SERVERFILE_DIR
- Removed DEV_DEPLOY_DIR indirection (was only used for development)
- Makefile expands defaults to ../dev-deploy/... directly for dev
2026-07-09 15:42:54 +02:00
MrFastwind
9aa6fca50e Fix embedded frontend serving: use fs.ReadFile instead of Gin FileFromFS
- FileFromFS with http.FS(embedFS) returned 301 redirects due to
  Gin setting c.Request.URL.Path to a relative path for http.FileServer
- Replace with direct fs.ReadFile + Gin c.Data, determining content
  type via mime.TypeByExtension
- Supports all asset types (JS, CSS, SVG, HTML) and SPA fallback
2026-07-09 15:34:50 +02:00
MrFastwind
bc0a252d7d Embed frontend dist into Go binary; remove frontend path from health
- New backend/embed package embeds frontend dist/ via //go:embed
- Go binary serves frontend from embedded FS (no external files needed)
- Dev mode uses placeholder dir (dev.txt) so Go compiles; Vite handles
  frontend in dev mode
- Makefile copies frontend/dist/ to backend/embed/dist/ during build
- Removed FRONTEND_DIR env var and filesystem serving fallback
- Removed frontend path from Health API response and Status page frontend
  section (only Served boolean remains)
- Removed frontendDir from Handler struct/constructor (unused)
2026-07-09 15:27:50 +02:00
MrFastwind
2d301b95b6 Add server health endpoint and status page
Backend:
- New /api/server/health endpoint returning server, paths, disk,
  mods, steamcmd, and frontend status
- Health endpoint checks directory existence/writability, disk usage,
  server binary, and frontend dist availability

Frontend:
- New Status page (route /status) with sections for Server, SteamCMD,
  Mods, Frontend, Directories (with exists/writable badges), and
  Disk Usage (with size formatting and used-percent coloring)
- Paths are clickable to copy and use start-truncation (ellipsis on
  the left) with native hover tooltip
- Health API client integration with 10s auto-refresh

Misc:
- Update .gitignore and Makefile, minor Layout nav addition
2026-07-09 15:22:43 +02:00
11 changed files with 446 additions and 24 deletions

2
.gitignore vendored
View File

@@ -1,6 +1,7 @@
node_modules/
dist/
frontend/dist/
backend/embed/dist/
*.exe
*.test
@@ -8,6 +9,7 @@ backend/arma3-web-server
data/
serverfiles/
dev-deploy/
.env
.DS_Store

View File

@@ -1,11 +1,11 @@
.PHONY: backend frontend build run clean dev
# Default paths — override via env or copy .env.example
SERVERFILE_DIR ?= ./serverfiles
MODS_DIR ?= ./serverfiles/mods
CFG_DIR ?= ./serverfiles/cfg
PROFILES_DIR ?= ./serverfiles/profiles
DATA_DIR ?= ../../data
# Default paths for dev — override via env
SERVERFILE_DIR ?= ../dev-deploy/serverfiles
MODS_DIR ?= ../dev-deploy/serverfiles/mods
CFG_DIR ?= ../dev-deploy/serverfiles/cfg
PROFILES_DIR ?= ../dev-deploy/serverfiles/profiles
DATA_DIR ?= ../dev-deploy/data
backend:
cd backend && go build -o arma3-web-server ./cmd/server/
@@ -13,15 +13,23 @@ backend:
frontend:
cd frontend && npm run build
build: backend frontend
.PHONY: copyfrontend
copyfrontend:
rm -rf backend/embed/dist
mkdir -p backend/embed/dist
cp -r frontend/dist/. backend/embed/dist/
build: frontend copyfrontend backend
run:
cd backend && SERVERFILE_DIR=$(SERVERFILE_DIR) MODS_DIR=$(MODS_DIR) CFG_DIR=$(CFG_DIR) PROFILES_DIR=$(PROFILES_DIR) DATA_DIR=$(DATA_DIR) GIN_MODE=debug go run ./cmd/server/
dev:
mkdir -p backend/embed/dist
test -f backend/embed/dist/dev.txt || touch backend/embed/dist/dev.txt
cd backend && SERVERFILE_DIR=$(SERVERFILE_DIR) MODS_DIR=$(MODS_DIR) CFG_DIR=$(CFG_DIR) PROFILES_DIR=$(PROFILES_DIR) DATA_DIR=$(DATA_DIR) GIN_MODE=debug go run ./cmd/server/ &
cd frontend && npm run dev
clean:
rm -f backend/arma3-web-server
rm -rf frontend/dist
rm -rf frontend/dist backend/embed/dist

View File

@@ -2,14 +2,18 @@ package main
import (
"context"
"io/fs"
"log"
"mime"
"net/http"
"os"
"os/signal"
"path/filepath"
"strings"
"syscall"
"time"
"arma3-web-server/embed"
"arma3-web-server/internal/api"
"arma3-web-server/internal/services"
@@ -17,13 +21,12 @@ import (
)
func main() {
dataDir := mustAbs(getEnv("DATA_DIR", filepath.Join("data")))
serverfileDir := mustAbs(getEnv("SERVERFILE_DIR", "serverfiles"))
modsDir := mustAbs(getEnv("MODS_DIR", "serverfiles/mods"))
cfgDir := mustAbs(getEnv("CFG_DIR", "serverfiles/cfg"))
profilesDir := mustAbs(getEnv("PROFILES_DIR", "serverfiles/profiles"))
serverfileDir := mustAbs(getEnv("SERVERFILE_DIR", "./serverfiles"))
dataDir := mustAbs(getEnv("DATA_DIR", "./data"))
modsDir := mustAbs(getEnv("MODS_DIR", filepath.Join(serverfileDir, "mods")))
cfgDir := mustAbs(getEnv("CFG_DIR", filepath.Join(serverfileDir, "cfg")))
profilesDir := mustAbs(getEnv("PROFILES_DIR", filepath.Join(serverfileDir, "profiles")))
listen := getEnv("LISTEN", ":8080")
frontendDir := mustAbs(getEnv("FRONTEND_DIR", filepath.Join("..", "frontend", "dist")))
log.Printf("data dir: %s", dataDir)
log.Printf("serverfile dir: %s", serverfileDir)
@@ -54,16 +57,31 @@ func main() {
r := gin.Default()
if fi, err := os.Stat(frontendDir); err == nil && fi.IsDir() {
r.Static("/assets", filepath.Join(frontendDir, "assets"))
r.StaticFile("/favicon.ico", filepath.Join(frontendDir, "favicon.ico"))
r.NoRoute(func(c *gin.Context) {
c.File(filepath.Join(frontendDir, "index.html"))
})
log.Printf("serving frontend from %s", frontendDir)
subFS, subErr := fs.Sub(embed.Frontend, "dist")
if subErr == nil {
if _, err := subFS.Open("index.html"); err == nil {
r.NoRoute(func(c *gin.Context) {
path := strings.TrimPrefix(c.Request.URL.Path, "/")
if path == "" {
path = "index.html"
}
data, err := fs.ReadFile(subFS, path)
if err == nil {
ct := mime.TypeByExtension(filepath.Ext(path))
if ct == "" {
ct = "text/html; charset=utf-8"
}
c.Data(http.StatusOK, ct, data)
return
}
data, _ = fs.ReadFile(subFS, "index.html")
c.Data(http.StatusOK, "text/html; charset=utf-8", data)
})
log.Print("serving embedded frontend")
}
}
handler := api.New(settings, configMgr, modlistMgr, process, steamcmd, scheduler, streamer, serverfileDir, modsDir, cfgDir, profilesDir)
handler := api.New(settings, configMgr, modlistMgr, process, steamcmd, scheduler, streamer, dataDir, serverfileDir, modsDir, cfgDir, profilesDir)
handler.SetupRoutes(r)
// Startup auto-tasks

6
backend/embed/embed.go Normal file
View File

@@ -0,0 +1,6 @@
package embed
import "embed"
//go:embed dist
var Frontend embed.FS

View File

@@ -0,0 +1,177 @@
package api
import (
"os"
"path/filepath"
"runtime"
"syscall"
"arma3-web-server/internal/services"
"github.com/gin-gonic/gin"
"golang.org/x/sys/unix"
)
type HealthResponse struct {
Server ServerHealth `json:"server"`
Paths []PathHealth `json:"paths"`
Mods ModsHealth `json:"mods"`
Disk []DiskHealth `json:"disk"`
SteamCMD SteamCMDHealth `json:"steamcmd"`
Frontend FrontendHealth `json:"frontend"`
}
type ServerHealth struct {
Running bool `json:"running"`
Installed bool `json:"installed"`
BinaryPath string `json:"binary_path,omitempty"`
}
type PathHealth struct {
Path string `json:"path"`
Exists bool `json:"exists"`
Writable bool `json:"writable"`
}
type ModsHealth struct {
WorkshopCount int `json:"workshop_count"`
LocalCount int `json:"local_count"`
}
type DiskHealth struct {
Path string `json:"path"`
TotalBytes uint64 `json:"total_bytes"`
FreeBytes uint64 `json:"free_bytes"`
UsedPercent float64 `json:"used_percent"`
}
type SteamCMDHealth struct {
Running bool `json:"running"`
}
type FrontendHealth struct {
Served bool `json:"served"`
}
func (h *Handler) Health(c *gin.Context) {
workshopMods := services.ListWorkshopMods(h.serverfileDir)
localMods := services.ListLocalMods(h.modsDir)
paths := h.checkPaths()
disk := h.checkDisk()
resp := HealthResponse{
Server: ServerHealth{
Running: h.process.IsRunning(),
Installed: checkServerBinary(h.serverfileDir),
BinaryPath: serverBinaryPath(h.serverfileDir),
},
Paths: paths,
Mods: ModsHealth{
WorkshopCount: len(workshopMods),
LocalCount: len(localMods),
},
Disk: disk,
SteamCMD: SteamCMDHealth{
Running: h.steamcmd.IsRunning(),
},
Frontend: FrontendHealth{
Served: true,
},
}
c.JSON(200, resp)
}
func (h *Handler) checkPaths() []PathHealth {
dirs := []string{
h.dataDir,
filepath.Join(h.dataDir, "modlists"),
h.serverfileDir,
h.modsDir,
h.cfgDir,
h.profilesDir,
}
result := make([]PathHealth, 0, len(dirs))
for _, dir := range dirs {
p := PathHealth{Path: dir}
fi, err := os.Stat(dir)
if err == nil && fi.IsDir() {
p.Exists = true
p.Writable = isWritable(dir)
}
result = append(result, p)
}
return result
}
func (h *Handler) checkDisk() []DiskHealth {
paths := []string{h.dataDir, h.serverfileDir}
seen := make(map[string]bool)
var result []DiskHealth
for _, p := range paths {
info, err := diskUsage(p)
if err != nil {
continue
}
key := info.Path
if seen[key] {
continue
}
seen[key] = true
result = append(result, info)
}
return result
}
func checkServerBinary(serverfileDir string) bool {
_, found := findServerBinary(serverfileDir)
return found
}
func serverBinaryPath(serverfileDir string) string {
path, _ := findServerBinary(serverfileDir)
return path
}
func findServerBinary(serverfileDir string) (string, bool) {
candidates := []string{"arma3server_x64"}
if runtime.GOOS == "windows" {
candidates = append(candidates, "arma3server_x64.exe")
} else {
candidates = append(candidates, "arma3server_x64.exe")
}
for _, name := range candidates {
p := filepath.Join(serverfileDir, name)
fi, err := os.Stat(p)
if err == nil && !fi.IsDir() {
return p, true
}
}
return "", false
}
func isWritable(path string) bool {
return unix.Access(path, unix.W_OK) == nil
}
func diskUsage(path string) (DiskHealth, error) {
var stat syscall.Statfs_t
if err := syscall.Statfs(path, &stat); err != nil {
return DiskHealth{}, err
}
total := stat.Blocks * uint64(stat.Bsize)
free := stat.Bfree * uint64(stat.Bsize)
var usedPercent float64
if total > 0 {
usedPercent = float64(total-free) / float64(total) * 100
}
return DiskHealth{
Path: path,
TotalBytes: total,
FreeBytes: free,
UsedPercent: usedPercent,
}, nil
}

View File

@@ -14,6 +14,7 @@ type Handler struct {
steamcmd *services.SteamCmdManager
scheduler *services.Scheduler
streamer *services.LogStreamer
dataDir string
serverfileDir string
modsDir string
cfgDir string
@@ -28,7 +29,7 @@ func New(
steamcmd *services.SteamCmdManager,
scheduler *services.Scheduler,
streamer *services.LogStreamer,
serverfileDir, modsDir, cfgDir, profilesDir string,
dataDir, serverfileDir, modsDir, cfgDir, profilesDir string,
) *Handler {
return &Handler{
settings: settings,
@@ -38,6 +39,7 @@ func New(
steamcmd: steamcmd,
scheduler: scheduler,
streamer: streamer,
dataDir: dataDir,
serverfileDir: serverfileDir,
modsDir: modsDir,
cfgDir: cfgDir,
@@ -59,6 +61,7 @@ func (h *Handler) SetupRoutes(r *gin.Engine) {
api.POST("/server/steamcmd/download-mod", h.SteamCMDDownloadMod)
api.GET("/server/steamcmd/status", h.SteamCMDStatus)
api.GET("/server/paths", h.ServerPaths)
api.GET("/server/health", h.Health)
api.GET("/server/logs", h.ListLogs)
api.GET("/server/logs/:file", h.GetLog)

View File

@@ -8,6 +8,7 @@ import Modlists from './pages/Modlists'
import ModlistEditor from './pages/ModlistEditor'
import Logs from './pages/Logs'
import Mods from './pages/Mods'
import Status from './pages/Status'
function App() {
return (
@@ -21,6 +22,7 @@ function App() {
<Route path="/modlists/:id" element={<ModlistEditor />} />
<Route path="/mods" element={<Mods />} />
<Route path="/logs" element={<Logs />} />
<Route path="/status" element={<Status />} />
<Route path="*" element={<Navigate to="/" replace />} />
</Routes>
</Layout>

View File

@@ -1,4 +1,4 @@
import type { ServerSettings, ServerPaths, ConfigInfo, Modlist, ModlistListItem, ModEntry, ModInfo } from '../types'
import type { ServerSettings, ServerPaths, ServerHealth, ConfigInfo, Modlist, ModlistListItem, ModEntry, ModInfo } from '../types'
const BASE = '/api'
@@ -24,6 +24,7 @@ export const settingsApi = {
status: () => request<{ running: boolean }>('/server/status'),
steamcmd: () => request<{ branch: string; user: string; platform: string }>('/server/steamcmd'),
paths: () => request<ServerPaths>('/server/paths'),
health: () => request<ServerHealth>('/server/health'),
}
export const configsApi = {

View File

@@ -8,6 +8,7 @@ const nav = [
{ to: '/modlists', label: 'Modlists', icon: '📦' },
{ to: '/mods', label: 'Mods', icon: '🗂' },
{ to: '/logs', label: 'Logs', icon: '📋' },
{ to: '/status', label: 'Status', icon: '📊' },
]
export default function Layout({ children }: { children: ReactNode }) {

View File

@@ -0,0 +1,175 @@
import { useQuery } from '@tanstack/react-query'
import { useCallback, useState } from 'react'
import { settingsApi } from '../api/client'
function fmtSize(bytes: number): string {
if (bytes === 0) return '0 B'
const units = ['B', 'KB', 'MB', 'GB', 'TB']
const i = Math.min(Math.floor(Math.log(bytes) / Math.log(1024)), units.length - 1)
return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + units[i]
}
function fmtPercent(p: number): string {
return p.toFixed(1) + '%'
}
function CopyPath({ path }: { path: string }) {
const [copied, setCopied] = useState(false)
const copy = useCallback(async () => {
try {
await navigator.clipboard.writeText(path)
setCopied(true)
setTimeout(() => setCopied(false), 1500)
} catch {}
}, [path])
return (
<span
onClick={copy}
title={path}
className="cursor-pointer flex items-center max-w-full font-mono text-xs hover:text-blue-400 transition-colors"
>
<span
className="overflow-hidden text-ellipsis whitespace-nowrap"
style={{ direction: 'rtl', textAlign: 'left' }}
>
<span style={{ direction: 'ltr', unicodeBidi: 'embed' }}>
{path}
</span>
</span>
{copied && <span className="ml-0.5 text-green-400 shrink-0"></span>}
</span>
)
}
export default function Status() {
const { data, isLoading, error } = useQuery({
queryKey: ['server-health'],
queryFn: settingsApi.health,
refetchInterval: 10000,
})
if (isLoading) return <p className="text-neutral-400">Loading status...</p>
if (error) return <p className="text-red-400">Failed to load status: {(error as Error).message}</p>
if (!data) return null
return (
<div>
<h2 className="text-2xl font-semibold mb-6">Deploy Status</h2>
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
<Section title="Server">
<StatusRow label="Running" value={data.server.running ? 'Yes' : 'No'} ok={data.server.running} />
<StatusRow label="Binary installed" value={data.server.installed ? 'Yes' : 'No'} ok={data.server.installed} />
{data.server.binary_path && (
<StatusRow label="Binary path" value={<CopyPath path={data.server.binary_path} />} />
)}
</Section>
<Section title="SteamCMD">
<StatusRow label="Running" value={data.steamcmd.running ? 'Yes' : 'No'} ok={!data.steamcmd.running} warn={data.steamcmd.running} />
</Section>
<Section title="Mods">
<StatusRow label="Workshop mods" value={String(data.mods.workshop_count)} />
<StatusRow label="Local mods" value={String(data.mods.local_count)} />
<StatusRow label="Total" value={String(data.mods.workshop_count + data.mods.local_count)} />
</Section>
<Section title="Frontend">
<StatusRow label="Served" value={data.frontend.served ? 'Yes' : 'No'} ok={data.frontend.served} />
</Section>
</div>
<div className="mt-6">
<Section title="Directories">
<table className="w-full text-sm table-fixed">
<thead>
<tr className="text-neutral-500 border-b border-neutral-800">
<th className="text-left py-2 pr-4 w-[55%]">Path</th>
<th className="text-center py-2 px-4 w-[22%]">Exists</th>
<th className="text-center py-2 px-4 w-[23%]">Writable</th>
</tr>
</thead>
<tbody>
{data.paths.map((p, i) => (
<tr key={i} className="border-b border-neutral-800/50">
<td className="py-2 pr-4 overflow-hidden"><CopyPath path={p.path} /></td>
<td className="text-center py-2 px-4">
<Badge ok={p.exists} label={p.exists ? 'Yes' : 'No'} />
</td>
<td className="text-center py-2 px-4">
<Badge ok={p.writable} label={p.writable ? 'Yes' : 'No'} />
</td>
</tr>
))}
</tbody>
</table>
</Section>
</div>
<div className="mt-6">
<Section title="Disk Usage">
<table className="w-full text-sm table-fixed">
<thead>
<tr className="text-neutral-500 border-b border-neutral-800">
<th className="text-left py-2 pr-4 w-[40%]">Path</th>
<th className="text-right py-2 px-4 w-[20%]">Total</th>
<th className="text-right py-2 px-4 w-[20%]">Free</th>
<th className="text-right py-2 px-4 w-[20%]">Used</th>
</tr>
</thead>
<tbody>
{data.disk.map((d, i) => (
<tr key={i} className="border-b border-neutral-800/50">
<td className="py-2 pr-4 overflow-hidden"><CopyPath path={d.path} /></td>
<td className="text-right py-2 px-4">{fmtSize(d.total_bytes)}</td>
<td className="text-right py-2 px-4">{fmtSize(d.free_bytes)}</td>
<td className="text-right py-2 px-4">
<span className={d.used_percent > 90 ? 'text-red-400' : d.used_percent > 75 ? 'text-yellow-400' : ''}>
{fmtPercent(d.used_percent)}
</span>
</td>
</tr>
))}
</tbody>
</table>
</Section>
</div>
</div>
)
}
function Section({ title, children }: { title: string; children: React.ReactNode }) {
return (
<div className="bg-neutral-900 border border-neutral-800 rounded-lg p-4">
<h3 className="font-medium mb-3 text-neutral-300">{title}</h3>
<div>{children}</div>
</div>
)
}
function StatusRow({ label, value, ok, warn }: { label: string; value: React.ReactNode; ok?: boolean; warn?: boolean }) {
return (
<div className="flex justify-between items-center py-1.5 text-sm">
<span className="text-neutral-500 shrink-0">{label}</span>
<span className="flex items-center gap-2 min-w-0 max-w-[65%]">
{ok !== undefined && <Dot color={ok ? 'bg-green-400' : 'bg-red-400'} />}
{warn && <Dot color="bg-yellow-400" />}
<span className={`min-w-0 overflow-hidden ${ok === false ? 'text-red-400' : warn ? 'text-yellow-400' : ''}`}>{value}</span>
</span>
</div>
)
}
function Badge({ ok, label }: { ok: boolean; label: string }) {
return (
<span className={`inline-block px-2 py-0.5 rounded text-xs font-medium ${ok ? 'bg-green-900/50 text-green-400' : 'bg-red-900/50 text-red-400'}`}>
{label}
</span>
)
}
function Dot({ color }: { color: string }) {
return <span className={`inline-block w-2 h-2 rounded-full ${color}`} />
}

View File

@@ -51,6 +51,35 @@ export interface ServerPaths {
profiles_dir: string
}
export interface ServerHealth {
server: {
running: boolean
installed: boolean
binary_path: string
}
paths: {
path: string
exists: boolean
writable: boolean
}[]
mods: {
workshop_count: number
local_count: number
}
disk: {
path: string
total_bytes: number
free_bytes: number
used_percent: number
}[]
steamcmd: {
running: boolean
}
frontend: {
served: boolean
}
}
export interface ModInfo {
id: string
name: string