1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-30 09:59:13 +08:00

add port flag to serve

This commit is contained in:
verokarhu
2014-08-06 18:19:09 +03:00
parent 0427d1efa1
commit bb924cab5b
2 changed files with 12 additions and 2 deletions

View File

@ -1,6 +1,7 @@
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)
}

View File

@ -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)