Commit bb924cab authored by verokarhu's avatar verokarhu

add port flag to serve

parent 0427d1ef
package main
import (
"errors"
"github.com/gonuts/flag"
"github.com/jbenet/commander"
h "github.com/jbenet/go-ipfs/http"
......@@ -14,11 +15,20 @@ var cmdIpfsServe = &commander.Command{
Flag: *flag.NewFlagSet("ipfs-serve", flag.ExitOnError),
}
func init() {
cmdIpfsServe.Flag.Uint("port", 80, "Port number")
}
func serveCmd(c *commander.Command, _ []string) error {
port := c.Flag.Lookup("port").Value.Get().(uint)
if port < 1 || port > 65535 {
return errors.New("invalid port number")
}
n, err := localNode()
if err != nil {
return err
}
return h.Serve("127.0.0.1", 80, n)
return h.Serve("127.0.0.1", port, n)
}
......@@ -24,7 +24,7 @@ func (i *ipfsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "%s", nd.Data)
}
func Serve(host string, port uint16, node *core.IpfsNode) error {
func Serve(host string, port uint, node *core.IpfsNode) error {
r := mux.NewRouter()
r.PathPrefix("/").Handler(&ipfsHandler{node}).Methods("GET")
http.Handle("/", r)
......
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