Преглед на файлове

Make server listen address configurable via flags

To improve the flexibility and configurability of the server, add a
`listen` flag to specify the server's listen address. This replaces
the hardcoded `localhost:3002` string.

This change addresses the need for configuring the server address
dynamically, facilitating easier deployment and testing.

Resolves: #8
patwie преди 1 година
родител
ревизия
5ae64e7aca
променени са 2 файла, в които са добавени 9 реда и са изтрити 10 реда
  1. 6 7
      README.md
  2. 3 3
      main.go

+ 6 - 7
README.md

@@ -58,10 +58,9 @@ docker build -t exalidraw-ui-build excalidraw -f ui-build.Dockerfile
 docker run -v ${PWD}/:/pwd/ -it exalidraw-ui-build cp -r /frontend /pwd
 ```
 
-(Optional) Replace `localhost:3002` inside of `main.go` with your domain name if you want to use a reverse proxy  
-(Optional) Replace `"ssl=!0", "ssl=0"` with `"ssl=!0", "ssl=1"` if you want to use HTTPS  
-(Optional) Replace `"ssl:!0", "ssl:0"` with `"ssl:!0", "ssl:1"` if you want to use HTTPS  
-(Optional) Change ip:port of Go webserver at the end of `main.go` if you want to customize it
+(Optional) Replace `localhost:3002` inside of `main.go` with your domain name if you want to use a reverse proxy
+(Optional) Replace `"ssl=!0", "ssl=0"` with `"ssl=!0", "ssl=1"` if you want to use HTTPS
+(Optional) Replace `"ssl:!0", "ssl:0"` with `"ssl:!0", "ssl:1"` if you want to use HTTPS
 
 Compile the Go application:
 
@@ -75,10 +74,10 @@ Example: `STORAGE_TYPE=sqlite DATA_SOURCE_NAME=/tmp/excalidb.sqlite`
 Start the server:
 
 ```bash
-go run main.go
+go run main.go --listen=":3002"
 
-STORAGE_TYPE=sqlite DATA_SOURCE_NAME=test.db go run main.go --loglevel debug
-STORAGE_TYPE=filesystem LOCAL_STORAGE_PATH=/tmp/excalidraw/ go run main.go --loglevel debug
+STORAGE_TYPE=sqlite DATA_SOURCE_NAME=test.db go run main.go --loglevel debug --listen=":3002"
+STORAGE_TYPE=filesystem LOCAL_STORAGE_PATH=/tmp/excalidraw/ go run main.go --loglevel debug --listen=":3002"
 ```
 
 Excalidraw Complete is now running on your machine, ready to bring your collaborative whiteboard ideas to life.

+ 3 - 3
main.go

@@ -244,6 +244,7 @@ func waitForShutdown(ioo *socketio.Server) {
 func main() {
 	// Define a log level flag
 	logLevel := flag.String("loglevel", "info", "Set the logging level: debug, info, warn, error, fatal, panic")
+    listenAddr := flag.String("listen", ":3002", "Set the server listen address")
 	flag.Parse()
 
 	// Set the log level
@@ -266,10 +267,9 @@ func main() {
 	})
 	r.Mount("/", handleUI())
 
-	addr := ":3002"
-	logrus.WithField("addr", addr).Info("starting server")
+	logrus.WithField("addr", *listenAddr).Info("starting server")
 	go func() {
-		if err := http.ListenAndServe(addr, r); err != nil {
+		if err := http.ListenAndServe(*listenAddr, r); err != nil {
 			logrus.WithField("event", "start server").Fatal(err)
 		}
 	}()