MCPcopy Create free account
hub / github.com/CPChain/chain / StartHTTPEndpoint

Function StartHTTPEndpoint

api/rpc/endpoints.go:26–52  ·  view source on GitHub ↗

StartHTTPEndpoint starts the HTTP RPC endpoint, configured with cors/vhosts/modules

(endpoint string, apis []API, modules []string, cors []string, vhosts []string)

Source from the content-addressed store, hash-verified

24
25// StartHTTPEndpoint starts the HTTP RPC endpoint, configured with cors/vhosts/modules
26func StartHTTPEndpoint(endpoint string, apis []API, modules []string, cors []string, vhosts []string) (net.Listener, *Server, error) {
27 // Generate the whitelist based on the allowed modules
28 whitelist := make(map[string]bool)
29 for _, module := range modules {
30 whitelist[module] = true
31 }
32 // Register all the APIs exposed by the services
33 handler := NewServer()
34 for _, api := range apis {
35 if whitelist[api.Namespace] || (len(whitelist) == 0 && api.Public) {
36 if err := handler.RegisterName(api.Namespace, api.Service); err != nil {
37 return nil, nil, err
38 }
39 log.Debug("HTTP registered", "namespace", api.Namespace)
40 }
41 }
42 // All APIs registered, start the HTTP listener
43 var (
44 listener net.Listener
45 err error
46 )
47 if listener, err = net.Listen("tcp", endpoint); err != nil {
48 return nil, nil, err
49 }
50 go NewHTTPServer(cors, vhosts, handler).Serve(listener)
51 return listener, handler, err
52}
53
54// StartWSEndpoint starts a websocket endpoint
55func StartWSEndpoint(endpoint string, apis []API, modules []string, wsOrigins []string, exposeAll bool) (net.Listener, *Server, error) {

Callers

nothing calls this directly

Calls 4

RegisterNameMethod · 0.95
NewServerFunction · 0.85
NewHTTPServerFunction · 0.85
DebugMethod · 0.80

Tested by

no test coverage detected