Fix serving the frontend from a path

pull/14/merge
Vasile Popescu 6 years ago
parent ca99245dc1
commit 2e15e457ab

@ -36,7 +36,7 @@ clean:
@echo "Cleaned"
runs: $(TTY_SERVER)
./$(TTY_SERVER) --url http://localhost:9090 --web_address :9090 --sender_address :7654
./$(TTY_SERVER) --url http://localhost:9090 --web_address :9090 --sender_address :7654 -frontend_path ./frontend/public
runc: $(TTY_SENDER)
./$(TTY_SENDER) --logfile output.log --useTLS=false

@ -67,14 +67,17 @@ func (server *TTYProxyServer) serveContent(w http.ResponseWriter, r *http.Reques
w.Header().Set("Content-Type", ctype)
w.Write(file)
} else {
_, err := os.Open(server.config.FrontendPath + string(os.PathSeparator) + name)
filePath := server.config.FrontendPath + string(os.PathSeparator) + name
_, err := os.Open(filePath)
if err != nil {
log.Errorf("Couldn't find resource: %s at %s", name, filePath)
w.WriteHeader(http.StatusNotFound)
return
}
log.Debugf("Serving %s from %s", name, filePath)
http.ServeFile(w, r, name)
http.ServeFile(w, r, filePath)
}
}

@ -15,6 +15,7 @@ func main() {
webAddress := flag.String("web_address", ":80", "The bind address for the web interface")
senderAddress := flag.String("sender_address", ":6543", "The bind address for the tty_sender connections")
url := flag.String("url", "http://localhost", "The public web URL the server will be accessible at")
frontendPath := flag.String("frontend_path", "frontend", "The path to the frontend resources")
flag.Parse()
log := MainLogger
@ -24,6 +25,7 @@ func main() {
WebAddress: *webAddress,
TTYSenderAddress: *senderAddress,
ServerURL: *url,
FrontendPath: *frontendPath,
}
server := NewTTYProxyServer(config)

Loading…
Cancel
Save