searcherside/handlers/api/v1/routes.go

35 lines
780 B
Go
Raw Normal View History

2024-06-06 20:08:51 +00:00
package v1
import (
"net/http"
"github.com/go-chi/chi/v5"
"github.com/go-chi/cors"
"github.com/go-chi/jwtauth/v5"
"github.com/lestrrat-go/jwx/v2/jwa"
)
func Mount(
r chi.Router,
authSecret []byte,
indexHandler IndexHandler,
searchHandler SearchHandler,
) {
r.Group(func(r chi.Router) {
jwtAuth := jwtauth.New(jwa.HS256.String(), authSecret, nil)
r.Use(jwtauth.Verify(jwtAuth, jwtauth.TokenFromHeader), jwtauth.Authenticator(jwtAuth))
r.Put("/index/{module}/{instance}", indexHandler.IngestIndex)
})
// Routes requiring CORS
r.Group(func(r chi.Router) {
r.Use(cors.Handler(cors.Options{
AllowedOrigins: []string{"*"},
AllowedMethods: []string{http.MethodGet},
}))
r.Get("/preview-search/{module}/{instance}", searchHandler.PreviewSearch)
})
}