github.com/koko1123/flow-go-1@v0.29.6/engine/access/rest/server.go (about) 1 package rest 2 3 import ( 4 "net/http" 5 "time" 6 7 "github.com/rs/cors" 8 "github.com/rs/zerolog" 9 10 "github.com/koko1123/flow-go-1/access" 11 "github.com/koko1123/flow-go-1/model/flow" 12 ) 13 14 // NewServer returns an HTTP server initialized with the REST API handler 15 func NewServer(backend access.API, listenAddress string, logger zerolog.Logger, chain flow.Chain) (*http.Server, error) { 16 17 router, err := newRouter(backend, logger, chain) 18 if err != nil { 19 return nil, err 20 } 21 22 c := cors.New(cors.Options{ 23 AllowedOrigins: []string{"*"}, 24 AllowedHeaders: []string{"*"}, 25 AllowedMethods: []string{ 26 http.MethodGet, 27 http.MethodPost, 28 http.MethodOptions, 29 http.MethodHead}, 30 }) 31 32 return &http.Server{ 33 Addr: listenAddress, 34 Handler: c.Handler(router), 35 WriteTimeout: time.Second * 15, 36 ReadTimeout: time.Second * 15, 37 IdleTimeout: time.Second * 60, 38 }, nil 39 }