add option to enable api server

This commit is contained in:
Joel Wetzell
2026-03-17 19:03:43 -05:00
parent 9c03ad2c14
commit 3d664fff67
4 changed files with 14 additions and 1 deletions

7
api.go
View File

@@ -15,6 +15,10 @@ import (
)
func (r *Router) startAPIServer(config config.ApiConfig) {
if !config.Enabled {
r.logger.Warn("API not enabled")
return
}
r.logger.Debug("starting API server", "port", config.Port)
mux := http.NewServeMux()
mux.HandleFunc("/ws", r.handleWebsocket)
@@ -36,6 +40,9 @@ func (r *Router) startAPIServer(config config.ApiConfig) {
}
func (r *Router) stopAPIServer() {
if r.apiServer == nil {
return
}
r.logger.Debug("stopping API server")
r.apiServerMu.Lock()
defer r.apiServerMu.Unlock()

View File

@@ -1,4 +1,5 @@
api:
enabled: true
port: 8080
modules:
- id: http

View File

@@ -7,6 +7,7 @@ type Config struct {
}
type ApiConfig struct {
Enabled bool `json:"enabled"`
Port int `json:"port"`
}
type ModuleConfig struct {

View File

@@ -8,6 +8,10 @@
"api": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean",
"description": "Whether the API server is enabled"
},
"port": {
"type": "integer",
"description": "Port for the API server to listen on"