From 16b2e39e1dbf3393108c2995819a3b2cfe918d69 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 20 Apr 2017 10:07:14 +0100 Subject: [PATCH] Add stub client-api-load-balancer binary --- .../cmd/client-api-load-balancer/main.go | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/github.com/matrix-org/dendrite/cmd/client-api-load-balancer/main.go diff --git a/src/github.com/matrix-org/dendrite/cmd/client-api-load-balancer/main.go b/src/github.com/matrix-org/dendrite/cmd/client-api-load-balancer/main.go new file mode 100644 index 000000000..dd26f20fc --- /dev/null +++ b/src/github.com/matrix-org/dendrite/cmd/client-api-load-balancer/main.go @@ -0,0 +1,58 @@ +package main + +import ( + "flag" + "fmt" + "os" +) + +const usage = `Usage: %s + +Create a single endpoint URL which clients can be pointed at. + +The client-server API in Dendrite is split across multiple processes +which listen on multiple ports. You cannot point a Matrix client at +any of those ports, as there will be unimplemented functionality. +In addition, all client-server API processes start with the additional +path prefix '/api', which Matrix clients will be unaware of. + +This tool will proxy requests for all client-server URLs and forward +them to their respective process. It will also add the '/api' path +prefix to incoming requests. + +Arguments: + +` + +var ( + syncServerURL = flag.String("sync-server-url", "", "The base URL of the listening 'dendrite-sync-server' process. E.g. 'http://localhost:4200'") + clientAPIURL = flag.String("client-api-url", "", "The base URL of the listening 'dendrite-client-api' process. E.g. 'http://localhost:4321'") + bindAddress = flag.String("bind-address", ":8008", "The listening port for the proxy.") +) + +func main() { + flag.Usage = func() { + fmt.Fprintf(os.Stderr, usage, os.Args[0]) + flag.PrintDefaults() + } + + flag.Parse() + + if *syncServerURL == "" { + flag.Usage() + fmt.Fprintln(os.Stderr, "no --sync-server-url specified.") + os.Exit(1) + } + + if *clientAPIURL == "" { + flag.Usage() + fmt.Fprintln(os.Stderr, "no --client-api-url specified.") + os.Exit(1) + } + + fmt.Println("Proxying requests to:") + fmt.Println(" /_matrix/client/r0/sync => ", *syncServerURL+"/api/_matrix/client/r0/sync") + fmt.Println(" /* => ", *clientAPIURL+"/api/*") + fmt.Println("Listening on %s", *bindAddress) + +}