Repository navigation
Add observe serve HTTP endpoint for VPS info - #18
Merged
Merged
Conversation
Expose the existing snapshot JSON over a read-only GET endpoint with CORS support so any frontend can fetch machine metrics. Includes optional bearer token auth, safe localhost default binding, and tests. Co-authored-by: Paul Contreras <pol-cova@users.noreply.github.com>
Allow overriding the listen port with --port while defaulting to automatically trying the next free port when 8080 (or the chosen port) is already in use. Use --auto-port=false to require an exact port. Co-authored-by: Paul Contreras <pol-cova@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
observe serve, a read-only HTTP server that exposes the same JSON snapshot asobserve snapshot. This lets any frontend fetch live VPS metrics with a simplefetch()call.Changes
observe servesubcommand with flags:--port(default8080) — override the listen port--auto-port(defaulttrue) — if the requested port is busy, try the next available port--bind(default127.0.0.1)--token(optional bearer auth)--path(default/info)--cors(default*)internal/serverpackage with CORS, OPTIONS preflight, and token authUsage
fetch("http://your-vps:8080/info", { headers: { Authorization: "Bearer your-secret" } }).then(r => r.json())Security
127.0.0.1by default0.0.0.0without a tokenTest plan
go test ./...go vet ./...go build