Skip to content

Commit

Permalink
handle CROS preflight requests
Browse files Browse the repository at this point in the history
  • Loading branch information
bparees committed Aug 21, 2023
1 parent 5bbf046 commit 472d1ff
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/wisdom/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func newStartServerCommand() *cobra.Command {
}

r.HandleFunc("/infer", h.InferHandler).Methods("POST")
r.HandleFunc("/infer", h.CORSHandler).Methods("OPTIONS")
//r.HandleFunc("/feedback", h.FeedbackHandler).Methods("POST")
r.HandleFunc("/login", h.HandleLogin)
r.HandleFunc("/githubcallback", h.HandleGithubCallback)
Expand Down
3 changes: 3 additions & 0 deletions pkg/filters/markdown/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ func MarkdownStripper(response *api.ModelResponse) (*api.ModelResponse, error) {

//response.Output = markdownRegex.ReplaceAllString(response.Output, "")
matches := markdownRegex.FindStringSubmatch(response.Output)
if len(matches) < 2 {
return response, fmt.Errorf("no markdown found in response")
}
response.Output = matches[1]
/*
node := gomarkdown.Parse([]byte(response.Output), nil)
Expand Down
3 changes: 3 additions & 0 deletions pkg/model/invoker.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package model

import (
log "github.com/sirupsen/logrus"

"github.com/openshift/wisdom/pkg/api"
"github.com/openshift/wisdom/pkg/filters"
)
Expand All @@ -11,6 +13,7 @@ func InvokeModel(input api.ModelInput, model api.Model, filter filters.Filter) (
if response == nil {
response = &api.ModelResponse{}
}
log.Debugf("model response: %#v", response)
if err != nil {
response.ErrorMessage = err.Error()
return response, err
Expand Down
7 changes: 7 additions & 0 deletions pkg/server/inference_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import (
"github.com/openshift/wisdom/pkg/model"
)

func (h *Handler) CORSHandler(w http.ResponseWriter, r *http.Request) {
http.Header.Add(w.Header(), "Access-Control-Allow-Origin", "*")
http.Header.Add(w.Header(), "Access-Control-Allow-Methods", "GET, POST, OPTIONS")
http.Header.Add(w.Header(), "Access-Control-Allow-Headers", "Content-Type, Authorization")

}

func (h *Handler) InferHandler(w http.ResponseWriter, r *http.Request) {
if !h.hasValidBearerToken(r) {
http.Error(w, "No valid bearer token found", http.StatusUnauthorized)
Expand Down

0 comments on commit 472d1ff

Please sign in to comment.