Skip to content

Commit

Permalink
updated dockerfile and service.go to work with railway.app
Browse files Browse the repository at this point in the history
  • Loading branch information
maxxfrazer committed Oct 24, 2022
1 parent 76f763f commit af11855
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ ADD . /go/src/github.com/AgoraIO-Community/agora-token-service

ARG APP_ID
ARG APP_CERTIFICATE
ARG SERVER_PORT
ENV APP_ID $APP_ID
ENV APP_CERTIFICATE $APP_CERTIFICATE
ENV SERVER_PORT $SERVER_PORT

# move to the working directory
WORKDIR $GOPATH/src/github.com/AgoraIO-Community/agora-token-service
Expand Down
6 changes: 3 additions & 3 deletions service/http_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func (s *Service) getRtcToken(c *gin.Context) {
log.Printf("rtc token\n")
log.Println("Generating RTC token")
// get param values
channelName, tokentype, uidStr, role, expireTimestamp, err := s.parseRtcParams(c)

Expand Down Expand Up @@ -41,7 +41,7 @@ func (s *Service) getRtcToken(c *gin.Context) {
}

func (s *Service) getRtmToken(c *gin.Context) {
log.Println("Generating RTM Token")
log.Println("Generating RTM token")
// get param values
uidStr, expireTimestamp, err := s.parseRtmParams(c)

Expand Down Expand Up @@ -73,7 +73,7 @@ func (s *Service) getRtmToken(c *gin.Context) {
}

func (s *Service) getBothTokens(c *gin.Context) {
log.Printf("dual token\n")
log.Println("Generating RTC and RTM tokens")
// get rtc param values
channelName, tokentype, uidStr, role, expireTimestamp, rtcParamErr := s.parseRtcParams(c)

Expand Down
14 changes: 10 additions & 4 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,22 @@ func NewService() *Service {

err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
log.Println("Error loading .env file")
}
appIDEnv, appIDExists := os.LookupEnv("APP_ID")
appCertEnv, appCertExists := os.LookupEnv("APP_CERTIFICATE")
serverPort, serverPortExists := os.LookupEnv("SERVER_PORT")
if !appIDExists || !appCertExists || len(appIDEnv) == 0 || len(appCertEnv) == 0 {
log.Fatal("FATAL ERROR: ENV not properly configured, check APP_ID and APP_CERTIFICATE")
log.Fatal("FATAL ERROR: ENV not properly configured, check .env file or APP_ID and APP_CERTIFICATE")
}
if !serverPortExists {
serverPort = "8080"
if !serverPortExists || len(serverPort) == 0 {
// Check $PORT, this is used by Railway.
port, portExists := os.LookupEnv("PORT")
if portExists && len(port) > 0 {
serverPort = port
} else {
serverPort = "8080"
}
}

s := &Service{
Expand Down
2 changes: 1 addition & 1 deletion service/tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ func (s *Service) generateRtcToken(channelName, uidStr, tokentype string, role r
log.Println(err)
return "", err
}
}
}

0 comments on commit af11855

Please sign in to comment.