This commit is contained in:
Harivansh Rathi 2026-04-01 03:45:34 +00:00
parent 4f174ec3a8
commit db1dea097f
81 changed files with 6263 additions and 545 deletions

10
apps/node-agent/README.md Normal file
View file

@ -0,0 +1,10 @@
# betterNAS Node Agent
Go service that runs on the NAS machine.
For the scaffold it does two things:
- serves `GET /health`
- serves a WebDAV export at `/dav/`
This is the first real storage-facing surface in the monorepo.

View file

@ -0,0 +1,46 @@
package main
import (
"log"
"net/http"
"os"
"time"
"golang.org/x/net/webdav"
)
func main() {
port := env("PORT", "8090")
exportPath := env("BETTERNAS_EXPORT_PATH", ".")
mux := http.NewServeMux()
mux.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
_, _ = w.Write([]byte("ok\n"))
})
dav := &webdav.Handler{
Prefix: "/dav",
FileSystem: webdav.Dir(exportPath),
LockSystem: webdav.NewMemLS(),
}
mux.Handle("/dav/", dav)
server := &http.Server{
Addr: ":" + port,
Handler: mux,
ReadHeaderTimeout: 5 * time.Second,
}
log.Printf("betterNAS node agent serving %s on :%s", exportPath, port)
log.Fatal(server.ListenAndServe())
}
func env(key, fallback string) string {
value, ok := os.LookupEnv(key)
if !ok || value == "" {
return fallback
}
return value
}

5
apps/node-agent/go.mod Normal file
View file

@ -0,0 +1,5 @@
module github.com/rathi/betternas/apps/node-agent
go 1.26.0
require golang.org/x/net v0.46.0

2
apps/node-agent/go.sum Normal file
View file

@ -0,0 +1,2 @@
golang.org/x/net v0.46.0 h1:giFlY12I07fugqwPuWJi68oOnpfqFnJIJzaIIm2JVV4=
golang.org/x/net v0.46.0/go.mod h1:Q9BGdFy1y4nkUwiLvT5qtyhAnEHgnQ/zd8PfU6nc210=

View file

@ -0,0 +1,12 @@
{
"name": "@betternas/node-agent",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "CGO_ENABLED=0 go run ./cmd/node-agent",
"build": "mkdir -p dist && CGO_ENABLED=0 go build -o dist/node-agent ./cmd/node-agent",
"lint": "CGO_ENABLED=0 go vet ./...",
"check-types": "CGO_ENABLED=0 go test ./...",
"test": "CGO_ENABLED=0 go test ./..."
}
}