Make server port configurable through environment variable LK_JWT_PORT, default 8080 (#17)

* Make server port configurable through environment variable LK_JWT_PORT, default 8080

* Update readme to reflect usage of LK_JWT_PORT environment variable
This commit is contained in:
Andrew
2024-03-19 04:32:16 -04:00
committed by GitHub
parent 186cc2038a
commit 94fa50e45f
2 changed files with 9 additions and 1 deletions

View File

@@ -9,3 +9,5 @@ To start the service locally:
```
$ LIVEKIT_URL="ws://somewhere" LIVEKIT_KEY=devkey LIVEKIT_SECRET=secret go run *.go
```
The listening port is configurable via the `LK_JWT_PORT` environment variable.

View File

@@ -19,6 +19,7 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"log"
"net/http"
"os"
@@ -174,6 +175,11 @@ func main() {
log.Fatal("LIVEKIT_KEY, LIVEKIT_SECRET and LIVEKIT_URL environment variables must be set")
}
lk_jwt_port := os.Getenv("LK_JWT_PORT")
if lk_jwt_port == "" {
lk_jwt_port = "8080"
}
log.Printf("LIVEKIT_KEY: %s and LIVEKIT_SECRET %s, LIVEKIT_URL %s", key, secret, lk_url)
handler := &Handler{
@@ -185,7 +191,7 @@ func main() {
http.HandleFunc("/sfu/get", handler.handle)
http.HandleFunc("/healthz", handler.healthcheck)
log.Fatal(http.ListenAndServe(":8080", nil))
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", lk_jwt_port), nil))
}
func getJoinToken(apiKey, apiSecret, room, identity string) (string, error) {