Commit a6eb3961 authored by Brian Tiger Chow's avatar Brian Tiger Chow

use --http flag to run expose IPFS HTTP API

parent 038ec6a5
...@@ -6,17 +6,19 @@ import ( ...@@ -6,17 +6,19 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context" context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
) ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
import ( homedir "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/mitchellh/go-homedir"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/mitchellh/go-homedir" fsnotify "github.com/jbenet/go-ipfs/Godeps/_workspace/src/gopkg.in/fsnotify.v1"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/gopkg.in/fsnotify.v1" commands "github.com/jbenet/go-ipfs/commands"
"github.com/jbenet/go-ipfs/core" core "github.com/jbenet/go-ipfs/core"
"github.com/jbenet/go-ipfs/core/coreunix" corehttp "github.com/jbenet/go-ipfs/core/corehttp"
"github.com/jbenet/go-ipfs/repo/config" coreunix "github.com/jbenet/go-ipfs/core/coreunix"
"github.com/jbenet/go-ipfs/repo/fsrepo" config "github.com/jbenet/go-ipfs/repo/config"
fsrepo "github.com/jbenet/go-ipfs/repo/fsrepo"
) )
var http = flag.Bool("http", false, "expose IPFS HTTP API")
var repoPath = flag.String("repo", os.Getenv("IPFS_PATH"), "IPFS_PATH to use") var repoPath = flag.String("repo", os.Getenv("IPFS_PATH"), "IPFS_PATH to use")
var watchPath = flag.String("path", ".", "the path to watch") var watchPath = flag.String("path", ".", "the path to watch")
...@@ -66,6 +68,21 @@ func run(ipfsPath, watchPath string) error { ...@@ -66,6 +68,21 @@ func run(ipfsPath, watchPath string) error {
} }
defer node.Close() defer node.Close()
if *http {
maddr, err := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/5001")
if err != nil {
return err
}
var opts = []corehttp.ServeOption{
corehttp.GatewayOption,
corehttp.WebUIOption,
corehttp.CommandsOption(cmdCtx(node, ipfsPath)),
}
if err := corehttp.ListenAndServe(node, maddr, opts...); err != nil {
return nil
}
}
for { for {
select { select {
case e := <-watcher.Events: case e := <-watcher.Events:
...@@ -152,3 +169,18 @@ func IsHidden(path string) bool { ...@@ -152,3 +169,18 @@ func IsHidden(path string) bool {
} }
return false return false
} }
func cmdCtx(node *core.IpfsNode, repoPath string) commands.Context {
return commands.Context{
// TODO deprecate this shit
Context: context.Background(),
Online: true,
ConfigRoot: repoPath,
LoadConfig: func(path string) (*config.Config, error) {
return node.Repo.Config(), nil
},
ConstructNode: func() (*core.IpfsNode, error) {
return node, nil
},
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment