mirror of
https://github.com/coalaura/up.git
synced 2025-07-17 21:44:35 +00:00
allow custom port
This commit is contained in:
@ -25,7 +25,7 @@ var (
|
|||||||
func main() {
|
func main() {
|
||||||
app := &cli.Command{
|
app := &cli.Command{
|
||||||
Name: "up",
|
Name: "up",
|
||||||
Usage: "UP client",
|
Usage: "up client",
|
||||||
Version: Version,
|
Version: Version,
|
||||||
ArgsUsage: "<file> <host>",
|
ArgsUsage: "<file> <host>",
|
||||||
UsageText: "up [options] <file> <host>",
|
UsageText: "up [options] <file> <host>",
|
||||||
|
@ -1,14 +1,18 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/coalaura/logger"
|
"github.com/coalaura/logger"
|
||||||
"github.com/coalaura/up/internal"
|
"github.com/coalaura/up/internal"
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
"github.com/patrickmn/go-cache"
|
"github.com/patrickmn/go-cache"
|
||||||
|
"github.com/urfave/cli/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -45,8 +49,36 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
app := &cli.Command{
|
||||||
|
Name: "up",
|
||||||
|
Usage: "up server",
|
||||||
|
Version: Version,
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.UintFlag{
|
||||||
|
Name: "port",
|
||||||
|
Aliases: []string{"p"},
|
||||||
|
Usage: "custom port",
|
||||||
|
Value: 7966,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Action: run,
|
||||||
|
EnableShellCompletion: true,
|
||||||
|
UseShortOptionHandling: true,
|
||||||
|
Suggest: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
err := app.Run(context.Background(), os.Args)
|
||||||
|
log.MustPanic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func run(_ context.Context, cmd *cli.Command) error {
|
||||||
log.Printf("up server %s\n", Version)
|
log.Printf("up server %s\n", Version)
|
||||||
|
|
||||||
|
port := cmd.Uint("port")
|
||||||
|
if port <= 0 || port > 65534 {
|
||||||
|
port = 7966
|
||||||
|
}
|
||||||
|
|
||||||
authorized, err := LoadAuthorizedKeys()
|
authorized, err := LoadAuthorizedKeys()
|
||||||
log.MustPanic(err)
|
log.MustPanic(err)
|
||||||
|
|
||||||
@ -66,13 +98,14 @@ func main() {
|
|||||||
r.Post("/receive", HandleReceiveRequest)
|
r.Post("/receive", HandleReceiveRequest)
|
||||||
|
|
||||||
srv := &http.Server{
|
srv := &http.Server{
|
||||||
Addr: ":7966",
|
Addr: fmt.Sprintf(":%d", port),
|
||||||
Handler: r,
|
Handler: r,
|
||||||
TLSConfig: &tls.Config{
|
TLSConfig: &tls.Config{
|
||||||
MinVersion: tls.VersionTLS12,
|
MinVersion: tls.VersionTLS12,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("Server listening on :7966")
|
log.Printf("Server listening on :%d\n", port)
|
||||||
srv.ListenAndServeTLS("cert.pem", "key.pem")
|
|
||||||
|
return srv.ListenAndServeTLS("cert.pem", "key.pem")
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user