summaryrefslogtreecommitdiff
path: root/internal/server/router.go
blob: 36c208377c0c3ba3901ae41944b16a89f307671b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package server

import (
	"fmt"
	"net/http"
	"time"
)

func (srv *server) ListenToRequests() {
	h := srv.actions
	mux := http.NewServeMux()
	server := &http.Server{
		Addr:         fmt.Sprintf("localhost:%d", srv.config.ServerConfig),
		Handler:      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 /", h.HandleForm)
	mux.HandleFunc("POST /done", h.HandleDoneAction)
	mux.HandleFunc("POST /login", h.HandleLogin)
	// mux.HandleFunc("POST /signup", h.HandleLogin)

	// ====== elements ======
	mux.HandleFunc("GET /showform", h.ServeShowForm)
	mux.HandleFunc("GET /hideform", h.ServeHideForm)

	fmt.Printf("Listening on %v\n", server.Addr)
	server.ListenAndServe()
}