diff --git a/internal/config/options.go b/internal/config/options.go index 368c0816..6ed1b12c 100644 --- a/internal/config/options.go +++ b/internal/config/options.go @@ -90,6 +90,7 @@ const ( defaultWatchdog = true defaultInvidiousInstance = "yewtu.be" defaultWebAuthn = false + defaultDisableAPI = false ) var defaultHTTPClientUserAgent = "Mozilla/5.0 (compatible; Miniflux/" + version.Version + "; +https://miniflux.app)" @@ -184,6 +185,7 @@ type options struct { invidiousInstance string mediaProxyPrivateKey []byte webAuthn bool + API bool } // NewOptions returns Options with default values. @@ -264,6 +266,7 @@ func NewOptions() *options { invidiousInstance: defaultInvidiousInstance, mediaProxyPrivateKey: crypto.GenerateRandomBytes(16), webAuthn: defaultWebAuthn, + API: !defaultDisableAPI, } } @@ -677,6 +680,11 @@ func (o *options) WebAuthn() bool { return o.webAuthn } +// EnableAPI returns true if API is enabled +func (o *options) EnableAPI() bool { + return o.API +} + // FilterEntryMaxAgeDays returns the number of days after which entries should be retained. func (o *options) FilterEntryMaxAgeDays() int { return o.filterEntryMaxAgeDays diff --git a/internal/config/parser.go b/internal/config/parser.go index f1fdf5ab..e6ef6f54 100644 --- a/internal/config/parser.go +++ b/internal/config/parser.go @@ -260,6 +260,8 @@ func (p *parser) parseLines(lines []string) (err error) { p.opts.invidiousInstance = parseString(value, defaultInvidiousInstance) case "WEBAUTHN": p.opts.webAuthn = parseBool(value, defaultWebAuthn) + case "DISABLE_API": + p.opts.API = !parseBool(value, defaultDisableAPI) } } diff --git a/internal/http/server/httpd.go b/internal/http/server/httpd.go index 32bf2275..a0535e9d 100644 --- a/internal/http/server/httpd.go +++ b/internal/http/server/httpd.go @@ -243,7 +243,9 @@ func setupHandler(store *storage.Storage, pool *worker.Pool) *mux.Router { fever.Serve(subrouter, store) googlereader.Serve(subrouter, store) - api.Serve(subrouter, store, pool) + if config.Opts.EnableAPI() { + api.Serve(subrouter, store, pool) + } ui.Serve(subrouter, store, pool) subrouter.HandleFunc("/healthcheck", readinessProbe).Name("healthcheck") diff --git a/internal/template/templates/common/settings_menu.html b/internal/template/templates/common/settings_menu.html index 1118483a..dfbb35f2 100644 --- a/internal/template/templates/common/settings_menu.html +++ b/internal/template/templates/common/settings_menu.html @@ -7,9 +7,11 @@