2024-07-22 21:00:21 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/asmogo/nws/config"
|
|
|
|
"github.com/asmogo/nws/exit"
|
2024-07-23 19:26:04 +00:00
|
|
|
"github.com/nbd-wtf/go-nostr"
|
2024-07-23 17:10:02 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"log/slog"
|
2024-07-22 21:00:21 +00:00
|
|
|
)
|
|
|
|
|
2024-07-23 17:10:02 +00:00
|
|
|
var httpsPort int32
|
|
|
|
var httpTarget string
|
|
|
|
|
2024-07-23 19:26:04 +00:00
|
|
|
const (
|
2024-07-23 19:49:15 +00:00
|
|
|
generateKeyMessage = "Generated new private key. Please set your environment using the new key, otherwise your key will be lost."
|
|
|
|
usagePort = "set the https reverse proxy port"
|
|
|
|
usageTarget = "set https reverse proxy target (your local service)"
|
2024-07-23 19:26:04 +00:00
|
|
|
)
|
|
|
|
|
2024-07-22 21:00:21 +00:00
|
|
|
func main() {
|
2024-07-23 17:10:02 +00:00
|
|
|
rootCmd := &cobra.Command{Use: "exit", Run: startExitNode}
|
2024-07-23 19:49:15 +00:00
|
|
|
rootCmd.Flags().Int32VarP(&httpsPort, "port", "p", 0, usagePort)
|
|
|
|
rootCmd.Flags().StringVarP(&httpTarget, "target", "t", "", usageTarget)
|
2024-07-23 17:10:02 +00:00
|
|
|
err := rootCmd.Execute()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func startExitNode(cmd *cobra.Command, args []string) {
|
|
|
|
|
2024-07-22 21:00:21 +00:00
|
|
|
// load the configuration
|
|
|
|
// from the environment
|
|
|
|
cfg, err := config.LoadConfig[config.ExitConfig]()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2024-07-23 19:49:15 +00:00
|
|
|
cfg.HttpsPort = httpsPort
|
|
|
|
cfg.HttpsTarget = httpTarget
|
|
|
|
|
2024-07-23 19:26:04 +00:00
|
|
|
if cfg.NostrPrivateKey == "" {
|
|
|
|
// generate new private key
|
|
|
|
cfg.NostrPrivateKey = nostr.GeneratePrivateKey()
|
|
|
|
slog.Warn(generateKeyMessage, "key", cfg.NostrPrivateKey)
|
|
|
|
}
|
2024-07-22 21:00:21 +00:00
|
|
|
// create a new gw server
|
|
|
|
// and start it
|
2024-07-23 17:10:02 +00:00
|
|
|
ctx := cmd.Context()
|
2024-07-22 21:00:21 +00:00
|
|
|
exitNode := exit.NewExit(ctx, cfg)
|
|
|
|
exitNode.ListenAndServe(ctx)
|
|
|
|
}
|