34 lines
780 B
Go
34 lines
780 B
Go
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)
|
|
})
|
|
}
|