Skip to content

Commit 47f3ebe

Browse files
committed
feat(api): add a preference to disable the API
1 parent 60cd7ff commit 47f3ebe

File tree

7 files changed

+27
-5
lines changed

7 files changed

+27
-5
lines changed

internal/config/options.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ const (
9090
defaultWatchdog = true
9191
defaultInvidiousInstance = "yewtu.be"
9292
defaultWebAuthn = false
93+
defaultDisableAPI = false
9394
)
9495

9596
var defaultHTTPClientUserAgent = "Mozilla/5.0 (compatible; Miniflux/" + version.Version + "; +https://miniflux.app)"
@@ -184,6 +185,7 @@ type options struct {
184185
invidiousInstance string
185186
mediaProxyPrivateKey []byte
186187
webAuthn bool
188+
API bool
187189
}
188190

189191
// NewOptions returns Options with default values.
@@ -264,6 +266,7 @@ func NewOptions() *options {
264266
invidiousInstance: defaultInvidiousInstance,
265267
mediaProxyPrivateKey: crypto.GenerateRandomBytes(16),
266268
webAuthn: defaultWebAuthn,
269+
API: !defaultDisableAPI,
267270
}
268271
}
269272

@@ -677,6 +680,11 @@ func (o *options) WebAuthn() bool {
677680
return o.webAuthn
678681
}
679682

683+
// EnableAPI returns true if API is enabled
684+
func (o *options) EnableAPI() bool {
685+
return o.API
686+
}
687+
680688
// FilterEntryMaxAgeDays returns the number of days after which entries should be retained.
681689
func (o *options) FilterEntryMaxAgeDays() int {
682690
return o.filterEntryMaxAgeDays

internal/config/parser.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ func (p *parser) parseLines(lines []string) (err error) {
260260
p.opts.invidiousInstance = parseString(value, defaultInvidiousInstance)
261261
case "WEBAUTHN":
262262
p.opts.webAuthn = parseBool(value, defaultWebAuthn)
263+
case "DISABLE_API":
264+
p.opts.API = !parseBool(value, defaultDisableAPI)
263265
}
264266
}
265267

internal/http/server/httpd.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,9 @@ func setupHandler(store *storage.Storage, pool *worker.Pool) *mux.Router {
243243

244244
fever.Serve(subrouter, store)
245245
googlereader.Serve(subrouter, store)
246-
api.Serve(subrouter, store, pool)
246+
if config.Opts.EnableAPI() {
247+
api.Serve(subrouter, store, pool)
248+
}
247249
ui.Serve(subrouter, store, pool)
248250

249251
subrouter.HandleFunc("/healthcheck", readinessProbe).Name("healthcheck")

internal/template/templates/common/settings_menu.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
<li>
88
<a href="{{ route "integrations" }}">{{ icon "third-party-services" }}{{ t "menu.integrations" }}</a>
99
</li>
10+
{{ if .apiEnabled }}
1011
<li>
1112
<a href="{{ route "apiKeys" }}">{{ icon "api" }}{{ t "menu.api_keys" }}</a>
1213
</li>
14+
{{ end }}
1315
<li>
1416
<a href="{{ route "sessions" }}">{{ icon "sessions" }}{{ t "menu.sessions" }}</a>
1517
</li>

internal/ui/ui.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,12 @@ func Serve(router *mux.Router, store *storage.Storage, pool *worker.Pool) {
132132
uiRouter.HandleFunc("/sessions/{sessionID}/remove", handler.removeSession).Name("removeSession").Methods(http.MethodPost)
133133

134134
// API Keys pages.
135-
uiRouter.HandleFunc("/keys", handler.showAPIKeysPage).Name("apiKeys").Methods(http.MethodGet)
136-
uiRouter.HandleFunc("/keys/{keyID}/delete", handler.deleteAPIKey).Name("deleteAPIKey").Methods(http.MethodPost)
137-
uiRouter.HandleFunc("/keys/create", handler.showCreateAPIKeyPage).Name("createAPIKey").Methods(http.MethodGet)
138-
uiRouter.HandleFunc("/keys/save", handler.saveAPIKey).Name("saveAPIKey").Methods(http.MethodPost)
135+
if config.Opts.EnableAPI() {
136+
uiRouter.HandleFunc("/keys", handler.showAPIKeysPage).Name("apiKeys").Methods(http.MethodGet)
137+
uiRouter.HandleFunc("/keys/{keyID}/delete", handler.deleteAPIKey).Name("deleteAPIKey").Methods(http.MethodPost)
138+
uiRouter.HandleFunc("/keys/create", handler.showCreateAPIKeyPage).Name("createAPIKey").Methods(http.MethodGet)
139+
uiRouter.HandleFunc("/keys/save", handler.saveAPIKey).Name("saveAPIKey").Methods(http.MethodPost)
140+
}
139141

140142
// OPML pages.
141143
uiRouter.HandleFunc("/export", handler.exportFeeds).Name("export").Methods(http.MethodGet)

internal/ui/view/view.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,6 @@ func New(tpl *template.Engine, r *http.Request, sess *session.Session) *view {
4545
"app_js_checksum": static.JavascriptBundles["app"].Checksum,
4646
"sw_js_checksum": static.JavascriptBundles["service-worker"].Checksum,
4747
"webAuthnEnabled": config.Opts.WebAuthn(),
48+
"apiEnabled": config.Opts.EnableAPI(),
4849
}}
4950
}

miniflux.1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,11 @@ Path to a secret key exposed as a file, it should contain $DATABASE_URL value\&.
235235
.br
236236
Default is empty\&.
237237
.TP
238+
.B API
239+
Enable or disable miniflux' API\&.
240+
.br
241+
Default is enabled\&.
242+
.TP
238243
.B DISABLE_HSTS
239244
Disable HTTP Strict Transport Security header if \fBHTTPS\fR is set\&.
240245
.br

0 commit comments

Comments
 (0)