Example #1
0
func newRestAPIHandler(node *core.OpenBazaarNode) (*restAPIHandler, error) {

	// Add the current node directory in case it's note already added.
	dirHash, aerr := ipfs.AddDirectory(node.Context, path.Join(node.RepoPath, "root"))
	if aerr != nil {
		log.Error(aerr)
		return nil, aerr
	}
	node.RootHash = dirHash

	prefixes := []string{"/ob/", "/wallet/"}
	i := &restAPIHandler{
		config: RestAPIConfig{
			Writable:     true,
			BlockList:    &corehttp.BlockList{},
			PathPrefixes: prefixes,
		},
		node: node,
	}
	return i, nil
}
Example #2
0
func makeHandler(n *core.OpenBazaarNode, ctx commands.Context, l net.Listener, options ...corehttp.ServeOption) (http.Handler, error) {
	topMux := http.NewServeMux()
	restAPI, err := newRestAPIHandler(n)
	if err != nil {
		return nil, err
	}
	wsAPI := newWSAPIHandler(ctx)
	n.Broadcast = wsAPI.h.Broadcast

	topMux.Handle("/ob/", restAPI)
	topMux.Handle("/wallet/", restAPI)
	topMux.Handle("/ws", wsAPI)

	mux := topMux
	for _, option := range options {
		var err error
		mux, err = option(n.IpfsNode, l, mux)
		if err != nil {
			return nil, err
		}
	}
	return topMux, nil
}