-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.go
69 lines (56 loc) · 1.61 KB
/
router.go
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package router
import (
"github.com/McCooll75/appchad/actions"
"github.com/McCooll75/appchad/api/auth"
"github.com/McCooll75/appchad/api/blogchad"
"github.com/McCooll75/appchad/api/users"
"github.com/McCooll75/appchad/handlers"
"github.com/McCooll75/appchad/websockets"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
)
// Set up and return router
func RouterSetup() *chi.Mux {
router := chi.NewRouter()
router.Use(middleware.Logger)
router.Use(middleware.RedirectSlashes)
// for not logged people
router.Group(func(r chi.Router) {
r.Use(guestMiddleware)
// api
r.Post("/api/auth/login", auth.Login)
r.Post("/api/auth/register", auth.Register)
// pages
r.Get("/", handlers.Auth)
r.Get("/auth", handlers.Auth)
})
// for logged people
router.Group(func(r chi.Router) {
r.Use(loggedInMiddleware)
// api
// blogchad
r.Post("/api/blogchad", blogchad.ArticlePost)
r.Post("/api/blogchad/comment", blogchad.CommentPost)
r.Post("/api/blogchad/vote", blogchad.VotePost)
// chad
r.Post("/api/chad/edit", users.UserEdit)
// actions
r.Get("/blogchad/delete", actions.BlogchadArticleDelete)
r.Get("/logout", actions.Logout)
// websocket
r.Get("/ws", websockets.Socket)
// pages
r.Group(func(r chi.Router) {
r.Use(headerMiddleware)
r.Get("/", handlers.Home)
r.Get("/home", handlers.Home)
r.Get("/chatchad", handlers.Chatchad)
r.Get("/chad/{id}", handlers.Chad)
// blogchad
r.Get("/blogchad", handlers.Blogchad)
r.Get("/blogchad/write", handlers.BlogchadWrite)
r.Get("/blogchad/article/{id}", handlers.BlogchadArticle)
})
})
return router
}