forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 6
/
mux.go
38 lines (30 loc) · 840 Bytes
/
mux.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
package http
import (
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
"github.com/rs/cors"
)
// NewMux returns a new server mux configured with the common defaults used across all
// stellar services.
func NewMux(behindProxy bool) *chi.Mux {
mux := chi.NewMux()
if behindProxy {
mux.Use(middleware.RealIP)
}
mux.Use(middleware.RequestID)
mux.Use(middleware.Recoverer)
mux.Use(LoggingMiddleware)
return mux
}
// NewAPIMux returns a new server mux configured with the common defaults used for a web API in
// stellar.
func NewAPIMux(behindProxy bool) *chi.Mux {
mux := NewMux(behindProxy)
c := cors.New(cors.Options{
AllowedOrigins: []string{"*"},
AllowedHeaders: []string{"*"},
AllowedMethods: []string{"GET", "PUT", "POST", "PATCH", "DELETE", "HEAD", "OPTIONS"},
})
mux.Use(c.Handler)
return mux
}