reprogl

Форк
0
/
routes.go 
74 строки · 3.9 Кб
1
package main
2

3
import (
4
	"net/http"
5

6
	"github.com/go-chi/chi/v5"
7
	"github.com/xelbot/reverse"
8
	"xelbot.com/reprogl/container"
9
	"xelbot.com/reprogl/handlers"
10
	"xelbot.com/reprogl/models"
11
)
12

13
func getRoutes(app *container.Application) *chi.Mux {
14
	siteMux := chi.NewRouter()
15
	siteMux.Get(reverse.Add("article", "/article/{slug}"), handlers.PageAction(app))
16
	siteMux.Get(reverse.Add("home", "/"), handlers.IndexAction(app))
17
	siteMux.Get(reverse.Add("blog-page", "/{page:[0-9]+}"), handlers.IndexAction(app))
18
	siteMux.Get(reverse.Add("category-first", "/category/{slug}"), handlers.CategoryAction(app))
19
	siteMux.Get(reverse.Add("category", "/category/{slug}/{page:[0-9]+}"), handlers.CategoryAction(app))
20
	siteMux.Get(reverse.Add("tag-first", "/tag/{slug}"), handlers.TagAction(app))
21
	siteMux.Get(reverse.Add("tag", "/tag/{slug}/{page:[0-9]+}"), handlers.TagAction(app))
22
	siteMux.Get(reverse.Add("info-page", "/about"), handlers.InfoAction(app))
23
	siteMux.Get("/info", func(w http.ResponseWriter, r *http.Request) {
24
		http.Redirect(w, r, "/about", http.StatusMovedPermanently)
25
	})
26
	siteMux.Get(reverse.Add("statistics", "/statistika"), handlers.StatisticsAction(app))
27
	siteMux.Get("/robots.txt", handlers.RobotsTXTAction)
28
	siteMux.Get("/humans.txt", handlers.HumansTXTAction)
29
	siteMux.Get("/favicon.ico", handlers.FavIconAction)
30
	siteMux.Get("/headers", handlers.HeadersDebug)
31
	siteMux.Get("/sitemap.xml", handlers.SitemapAction(app))
32
	siteMux.Get(reverse.Add("feed-atom", "/feed/atom"), handlers.FeedAction(app, models.AtomFeedType))
33
	siteMux.Get(reverse.Add("feed-rss", "/feed/rss"), handlers.FeedAction(app, models.RssFeedType))
34
	siteMux.Post(reverse.Add("add-comment-dummy", "/add-comment"), handlers.AddCommentDummy)
35
	siteMux.Post(reverse.Add("add-comment", "/add-ajax-comment"), handlers.AddComment(app))
36
	siteMux.Post("/purge-cache", handlers.PurgeCache(app))
37
	siteMux.Get("/images/avatar/{hash:[0-9A-Z]+}.png", handlers.AvatarGenerator(app))
38
	siteMux.Get("/images/avatar/{hash:[0-9A-Z]+}.w{size:[0-9]+}.png", handlers.AvatarGeneratorWithSize(app))
39
	siteMux.Get(reverse.Add("profile", "/profile"), handlers.ProfileAction(app))
40
	siteMux.Post("/profile", handlers.UpdateProfile(app))
41
	siteMux.Get("/email-unsubscribe/{hash:[0-9A-Z]+}", handlers.EmailUnsubscribe(app))
42
	siteMux.Post("/email-unsubscribe/{hash:[0-9A-Z]+}", handlers.EmailUnsubscribePost(app))
43
	siteMux.Get(reverse.Add("login", "/login"), handlers.LoginAction(app))
44
	siteMux.Post("/login", handlers.LoginCheck(app))
45
	siteMux.Get(reverse.Add("logout", "/logout"), handlers.LogoutAction)
46

47
	oauthMux := chi.NewRouter()
48
	siteMux.Mount(reverse.Group("oauth", "/oauth"), oauthMux)
49

50
	oauthMux.Get(reverse.AddGr("oauth-authorize", "oauth", "/authorize/{provider}"), handlers.OAuthLogin(app))
51
	oauthMux.Get(reverse.AddGr("oauth-verification", "oauth", "/verification/{provider}"), handlers.OAuthCallback(app))
52
	oauthMux.Get(reverse.AddGr("oauth-check", "oauth", "/check/{request_id}"), handlers.OAuthCheckState(app))
53

54
	fragmentsMux := chi.NewRouter()
55
	siteMux.Mount(reverse.Group("fragments", "/_fragment"), fragmentsMux)
56

57
	fragmentsMux.Get(reverse.AddGr("fragment-categories", "fragments", "/categories"), handlers.CategoriesFragment(app))
58
	fragmentsMux.Get(reverse.AddGr("fragment-comments",
59
		"fragments",
60
		"/comments/{article_id:[0-9]+}/{disabled_flag:(?:e|d)}/{last_time:[0-9]+}"),
61
		handlers.CommentsFragment(app),
62
	)
63
	fragmentsMux.Get(reverse.AddGr("fragment-recent-posts",
64
		"fragments",
65
		"/recent-posts/{article_id:[0-9]+}"),
66
		handlers.RecentPostsFragment(app),
67
	)
68
	fragmentsMux.Get(reverse.AddGr("fragment-war", "fragments", "/war-in-ukraine"), handlers.DaysOfWarCounter)
69
	fragmentsMux.Get(reverse.AddGr("auth-navigation", "fragments", "/auth-navigation"), handlers.AuthNavigation(app))
70
	fragmentsMux.Get(reverse.AddGr("fragment-markdown", "fragments", "/markdown/{filename}"), handlers.MarkdownAction(app))
71
	fragmentsMux.Get(reverse.AddGr("menu-auth", "fragments", "/menu-auth"), handlers.MenuAuth(app))
72

73
	return siteMux
74
}
75

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.