Пример #1
0
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
	}
}
Пример #2
0
func CommandsOption(cctx commands.Context) ServeOption {
	return func(n *core.IpfsNode, mux *http.ServeMux) (*http.ServeMux, error) {

		cfg := &cmdsHttp.ServerConfig{
			CORSOpts: &cors.Options{
				AllowedMethods: []string{"GET", "POST", "PUT"},
			},
		}

		addHeadersFromConfig(cfg, n.Repo.Config())
		addCORSFromEnv(cfg)

		cmdHandler := cmdsHttp.NewHandler(cctx, corecommands.Root, cfg)
		mux.Handle(cmdsHttp.ApiPath+"/", cmdHandler)
		return mux, nil
	}
}
Пример #3
0
func commandsOption(cctx commands.Context, command *commands.Command) ServeOption {
	return func(n *core.IpfsNode, l net.Listener, mux *http.ServeMux) (*http.ServeMux, error) {

		cfg := cmdsHttp.NewServerConfig()
		cfg.SetAllowedMethods("GET", "POST", "PUT")
		rcfg, err := n.Repo.Config()
		if err != nil {
			return nil, err
		}

		addHeadersFromConfig(cfg, rcfg)
		addCORSFromEnv(cfg)
		addCORSDefaults(cfg)
		patchCORSVars(cfg, l.Addr())

		cmdHandler := cmdsHttp.NewHandler(cctx, command, cfg)
		mux.Handle(cmdsHttp.ApiPath+"/", cmdHandler)
		return mux, nil
	}
}