partial bug fix

This commit is contained in:
Joshua Ashton
2024-11-01 14:50:14 -06:00
committed by Violet Ash
parent a79e6ce975
commit 8c8652ce67
4 changed files with 12 additions and 12 deletions
@@ -208,12 +208,12 @@ func validateHash(decrypted string, hash string) bool {
// Authentication takes place solely on the backend. // Authentication takes place solely on the backend.
func ServeAuthentication( func ServeAuthentication(
router *mux.Router, router *mux.Router,
port int, port string,
) { ) {
// TODO: Add error handling // TODO: Add error handling
authR := router.Host("http://localhost").Subrouter() authR := router.Host("http://localhost").Subrouter()
authSrv := &http.Server{ authSrv := &http.Server{
Addr: "0.0.0.0:" + string(port), Addr: "0.0.0.0:" + port,
WriteTimeout: time.Second * 15, WriteTimeout: time.Second * 15,
ReadTimeout: time.Second * 15, ReadTimeout: time.Second * 15,
IdleTimeout: time.Second * 60, IdleTimeout: time.Second * 60,
@@ -226,5 +226,5 @@ func ServeAuthentication(
} }
}() }()
log.Println("Auth server is running on port " + string(port)) log.Println("Auth server is running on port " + port)
} }
@@ -249,9 +249,9 @@ func serve() {
r := mux.NewRouter() r := mux.NewRouter()
//for _, webpage := range config.Webpages { //for _, webpage := range config.Webpages {
//} //}
ServePage(r, config.WebpageDir, "/", config.WebpagePort) ServePage(r, config.WebpageDir, "/", string(config.WebpagePort))
ServeApi(r, config.API, endpoint, function, config.APIPort) ServeApi(r, config.API, endpoint, function, string(config.APIPort))
ServeAuthentication(r, config.AuthPort) ServeAuthentication(r, string(config.AuthPort))
addr := "0.0.0.0:" + string(config.RouterPort) addr := "0.0.0.0:" + string(config.RouterPort)
srv := &http.Server{ srv := &http.Server{
@@ -15,7 +15,7 @@ func ServeApi(
domain string, domain string,
endpoint []string, endpoint []string,
function []func(http.ResponseWriter, *http.Request), function []func(http.ResponseWriter, *http.Request),
port int, port string,
) { ) {
// TODO: Add error handling // TODO: Add error handling
apiR := router.Host(domain).Subrouter() apiR := router.Host(domain).Subrouter()
@@ -25,7 +25,7 @@ func ServeApi(
} }
apiSrv := &http.Server{ apiSrv := &http.Server{
Addr: "0.0.0.0:" + string(port), Addr: "0.0.0.0:" + port,
WriteTimeout: time.Second * 15, WriteTimeout: time.Second * 15,
ReadTimeout: time.Second * 15, ReadTimeout: time.Second * 15,
IdleTimeout: time.Second * 60, IdleTimeout: time.Second * 60,
@@ -38,5 +38,5 @@ func ServeApi(
} }
}() }()
log.Println("API server is running on port " + string(port)) log.Println("API server is running on port " + port)
} }
@@ -8,11 +8,11 @@ import (
) )
// Serve a directory to a port. // Serve a directory to a port.
func ServePage(router *mux.Router, dest string, path string, port int) { func ServePage(router *mux.Router, dest string, path string, port string) {
router.PathPrefix(path).Handler(http.FileServer(http.Dir(dest))) router.PathPrefix(path).Handler(http.FileServer(http.Dir(dest)))
srv := &http.Server{ srv := &http.Server{
Addr: "0.0.0.0: " + string(port), Addr: "0.0.0.0: " + port,
// Good practice to set timeouts to avoid Slowloris attacks. // Good practice to set timeouts to avoid Slowloris attacks.
WriteTimeout: time.Second * 15, WriteTimeout: time.Second * 15,
ReadTimeout: time.Second * 15, ReadTimeout: time.Second * 15,
@@ -27,5 +27,5 @@ func ServePage(router *mux.Router, dest string, path string, port int) {
} }
}() }()
log.Println("Web server is running on port " + string(port)) log.Println("Web server is running on port " + port)
} }