mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-22 02:47:48 +08:00
Each option now additionally returns the mux to be used by future options. If
every options returns the mux it was passed, the current behavior is unchanged.
However, if the option returns an a new mux, it can mediate requests to handlers
provided by future options:
return func(n *core.IpfsNode, mux *http.ServeMux) (*http.ServeMux, error) {
childMux := http.NewServeMux()
mux.Handle("/", handlerThatDelegatesToChildMux)
return childMux, nil
}
License: MIT
Signed-off-by: Kevin Wallace <kevin@pentabarf.net>
26 lines
608 B
Go
26 lines
608 B
Go
package corehttp
|
|
|
|
import (
|
|
"net/http"
|
|
"os"
|
|
|
|
commands "github.com/jbenet/go-ipfs/commands"
|
|
cmdsHttp "github.com/jbenet/go-ipfs/commands/http"
|
|
core "github.com/jbenet/go-ipfs/core"
|
|
corecommands "github.com/jbenet/go-ipfs/core/commands"
|
|
)
|
|
|
|
const (
|
|
// TODO rename
|
|
originEnvKey = "API_ORIGIN"
|
|
)
|
|
|
|
func CommandsOption(cctx commands.Context) ServeOption {
|
|
return func(n *core.IpfsNode, mux *http.ServeMux) (*http.ServeMux, error) {
|
|
origin := os.Getenv(originEnvKey)
|
|
cmdHandler := cmdsHttp.NewHandler(cctx, corecommands.Root, origin)
|
|
mux.Handle(cmdsHttp.ApiPath+"/", cmdHandler)
|
|
return mux, nil
|
|
}
|
|
}
|