summaryrefslogtreecommitdiff
path: root/internal/server/router.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/server/router.go')
-rw-r--r--internal/server/router.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/internal/server/router.go b/internal/server/router.go
new file mode 100644
index 0000000..989766c
--- /dev/null
+++ b/internal/server/router.go
@@ -0,0 +1,31 @@
+package server
+
+import (
+ "fmt"
+ "net/http"
+ "time"
+)
+
+func (srv *server) ListenToRequests() {
+ h := srv.actions
+ mux := http.NewServeMux()
+ server := &http.Server{
+ Addr: fmt.Sprintf("localhost:%s", srv.config.ServerConfig.Port),
+ Handler: h.GetSession(mux),
+ ReadTimeout: time.Second * 5,
+ WriteTimeout: time.Second * 5,
+ }
+
+ fs := http.FileServer(http.Dir("assets/"))
+ mux.Handle("GET /assets/", http.StripPrefix("/assets/", fs))
+
+ mux.HandleFunc("GET /ping", h.Ping)
+ mux.HandleFunc("GET /", h.MainPage)
+ mux.HandleFunc("POST /login", h.HandleLogin)
+ mux.HandleFunc("POST /signup", h.HandleSignup)
+
+ // ====== elements ======
+
+ fmt.Println("Listening", "addr", server.Addr)
+ server.ListenAndServe()
+}