diff --git a/dgraph/cmd/alpha/dashboard.go b/dgraph/cmd/alpha/dashboard.go index 4a046394d09..bd5612a196d 100644 --- a/dgraph/cmd/alpha/dashboard.go +++ b/dgraph/cmd/alpha/dashboard.go @@ -41,7 +41,11 @@ func homeHandler(w http.ResponseWriter, r *http.Request) { // Used to return a list of keywords, so that UI can show them for autocompletion. func keywordHandler(w http.ResponseWriter, r *http.Request) { x.AddCorsHeaders(w) - if r.Method != "GET" { + if r.Method == http.MethodOptions { + return + } + + if r.Method != http.MethodGet { http.Error(w, x.ErrorInvalidMethod, http.StatusBadRequest) return } diff --git a/dgraph/cmd/alpha/http_test.go b/dgraph/cmd/alpha/http_test.go index f3b5e9ce852..041dde4838e 100644 --- a/dgraph/cmd/alpha/http_test.go +++ b/dgraph/cmd/alpha/http_test.go @@ -806,3 +806,14 @@ func TestDrainingMode(t *testing.T) { setDrainingMode(t, false) runRequests(false) } + +func TestOptionsForUiKeywords(t *testing.T) { + req, err := http.NewRequest(http.MethodOptions, fmt.Sprintf("%s/ui/keywords", addr), nil) + require.NoError(t, err) + + client := &http.Client{} + + resp, err := client.Do(req) + require.NoError(t, err) + require.True(t, resp.StatusCode >= 200 && resp.StatusCode < 300) +}