-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.go
46 lines (34 loc) · 1.3 KB
/
handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package handles
import (
"github.com/gorilla/mux"
"github.com/louisevanderlith/droxolite/open"
"github.com/rs/cors"
"net/http"
)
func SetupRoutes(audience, issuer string) http.Handler {
mw := open.BearerMiddleware(audience, issuer)
r := mux.NewRouter()
r.HandleFunc("/{type:[a-z]+}/{key:[0-9]+\\x60[0-9]+}", ViewType).Methods(http.MethodGet)
r.HandleFunc("/messages", GetMessages).Methods(http.MethodGet)
r.HandleFunc("/messages/{key:[0-9]+\\x60[0-9]+}", ViewMessage).Methods(http.MethodGet)
r.HandleFunc("/messages/{pagesize:[A-Z][0-9]+}", SearchMessage).Methods(http.MethodGet)
r.HandleFunc("/messages/{pagesize:[A-Z][0-9]+}/{hash:[a-zA-Z0-9]+={0,2}}", SearchMessage).Methods(http.MethodGet)
r.HandleFunc("/messages", CreateMessage).Methods(http.MethodPost)
r.HandleFunc("/messages/{key:[0-9]+\\x60[0-9]+}", UpdateMessage).Methods(http.MethodPut)
r.Use(mw.Handler)
corsOpts := cors.New(cors.Options{
AllowedOrigins: []string{"*"}, //you service is available and allowed for this base url
AllowedMethods: []string{
http.MethodGet,
http.MethodPost,
http.MethodDelete,
http.MethodOptions,
http.MethodHead,
},
AllowCredentials: true,
AllowedHeaders: []string{
"*", //or you can your header key values which you are using in your application
},
})
return corsOpts.Handler(r)
}