commit eda9cccce7704e65905f26fa0bfc94f055e498e2
parent 27038bbf56cd938d58a8e52da8dec6a65c91f569
Author: weetat <wtenison@protonmail.com>
Date: Wed, 26 Feb 2025 22:48:57 +0000
Move route setup into makeServerRoutes()
Diffstat:
3 files changed, 27 insertions(+), 23 deletions(-)
diff --git a/src/miki/miki.go b/src/miki/miki.go
@@ -7,7 +7,7 @@ import (
func main() {
mfs.Init()
-
mnw.Init()
+
mnw.Exec()
}
diff --git a/src/network/network.go b/src/network/network.go
@@ -1,7 +1,6 @@
package network
import (
- "fmt"
"log"
"net/http"
"os"
@@ -50,27 +49,9 @@ func Init() {
log.Panicf("__PANIC\tnetwork:Init:%s", err)
}
- //// SET UP SERVER MUX
+ //// MAKE SERVER ROUTES
- mux = http.NewServeMux()
-
- mux.Handle("/web/", http.StripPrefix("/web/", http.FileServer(http.Dir(mfs.Dirs["web"]))))
-
- mux.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
- http.ServeFile(w, r, filepath.Join(mfs.Dirs["web"], "/global/favicon.ico"))
- })
-
- mux.HandleFunc("/home", handlePageDefault)
- mux.HandleFunc("/edit", handlePageDefault)
-
- mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
- if r.URL.Path == "/" {
- http.Redirect(w, r, "/home", http.StatusMovedPermanently)
- return
- } else {
- http.NotFound(w, r)
- }
- })
+ makeServerRoutes()
}
func Exec() {
@@ -78,6 +59,6 @@ func Exec() {
//// RUN SERVER
if _err := http.ListenAndServeTLS(":"+serverInfo.port, serverInfo.certFile, serverInfo.keyFile, mux); _err != nil {
- fmt.Printf("_ERROR\tnetwork:Exec:ListenAndServeTLS:%s", _err)
+ log.Printf("_ERROR\tnetwork:Exec:ListenAndServeTLS:%s", _err)
}
}
diff --git a/src/network/routes.go b/src/network/routes.go
@@ -11,6 +11,29 @@ import (
var mux *http.ServeMux
+func makeServerRoutes() {
+
+ mux = http.NewServeMux()
+
+ mux.Handle("/web/", http.StripPrefix("/web/", http.FileServer(http.Dir(mfs.Dirs["web"]))))
+
+ mux.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
+ http.ServeFile(w, r, filepath.Join(mfs.Dirs["web"], "/global/favicon.ico"))
+ })
+
+ mux.HandleFunc("/home", handlePageDefault)
+ mux.HandleFunc("/edit", handlePageDefault)
+
+ mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+ if r.URL.Path == "/" {
+ http.Redirect(w, r, "/home", http.StatusMovedPermanently)
+ return
+ } else {
+ http.NotFound(w, r)
+ }
+ })
+}
+
func handlePageDefault(w http.ResponseWriter, r *http.Request) {
// Produce URL path to directory relation.