mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-30 18:13:54 +08:00
add port flag to serve
This commit is contained in:
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user