mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 21:56:50 -04:00
Launch Browser on Server Start
This commit is contained in:
23
web.go
23
web.go
@@ -11,6 +11,9 @@ import (
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const httpPort = 8080
|
||||
@@ -32,6 +35,26 @@ func ServeWebInterface() {
|
||||
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static/"))))
|
||||
http.Handle("/", newHandler())
|
||||
log.Printf("Serving HTTP requests on port %d", httpPort)
|
||||
|
||||
// Open in Default Web Browser
|
||||
// Necessary to Authenticate
|
||||
url := "http://localhost:"+strconv.Itoa(httpPort)
|
||||
var err error
|
||||
switch runtime.GOOS {
|
||||
case "linux":
|
||||
err = exec.Command("xdg-open", url).Start()
|
||||
case "darwin":
|
||||
err = exec.Command("open", url).Start()
|
||||
case "windows":
|
||||
err = exec.Command(`rundll32.exe`, "url.dll,FileProtocolHandler", url).Start()
|
||||
default:
|
||||
err = fmt.Errorf("unsupported platform")
|
||||
}
|
||||
if err != nil {
|
||||
println(err.Error())
|
||||
}
|
||||
|
||||
// Start Server
|
||||
http.ListenAndServe(fmt.Sprintf(":%d", httpPort), nil)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user