You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
903 B
44 lines
903 B
package main
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
|
|
"teraclone/internal/routes"
|
|
"teraclone/internal/service"
|
|
)
|
|
|
|
func main() {
|
|
runServer()
|
|
}
|
|
|
|
func runServer() {
|
|
port := os.Getenv("PORT")
|
|
if port == "" {
|
|
port = "8083"
|
|
}
|
|
apiUpstream := os.Getenv("TERACLONE_API_UPSTREAM")
|
|
if apiUpstream == "" {
|
|
apiUpstream = "http://127.0.0.1:8082"
|
|
}
|
|
sessionUpstream := os.Getenv("TERACLONE_SESSION_UPSTREAM")
|
|
if sessionUpstream == "" {
|
|
sessionUpstream = "http://127.0.0.1:8081"
|
|
}
|
|
|
|
// Device state and accounts belong exclusively to tera-api.
|
|
appService := service.NewStatelessAppService()
|
|
|
|
mux := http.NewServeMux()
|
|
if err := routes.RegisterWithSessionUpstream(mux, appService, apiUpstream, sessionUpstream); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
addr := ":" + port
|
|
log.Printf("server listening on http://localhost%s", addr)
|
|
|
|
if err := http.ListenAndServe(addr, mux); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|