reprogl
/
routes.go
74 строки · 3.9 Кб
1package main2
3import (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
13func getRoutes(app *container.Application) *chi.Mux {14siteMux := chi.NewRouter()15siteMux.Get(reverse.Add("article", "/article/{slug}"), handlers.PageAction(app))16siteMux.Get(reverse.Add("home", "/"), handlers.IndexAction(app))17siteMux.Get(reverse.Add("blog-page", "/{page:[0-9]+}"), handlers.IndexAction(app))18siteMux.Get(reverse.Add("category-first", "/category/{slug}"), handlers.CategoryAction(app))19siteMux.Get(reverse.Add("category", "/category/{slug}/{page:[0-9]+}"), handlers.CategoryAction(app))20siteMux.Get(reverse.Add("tag-first", "/tag/{slug}"), handlers.TagAction(app))21siteMux.Get(reverse.Add("tag", "/tag/{slug}/{page:[0-9]+}"), handlers.TagAction(app))22siteMux.Get(reverse.Add("info-page", "/about"), handlers.InfoAction(app))23siteMux.Get("/info", func(w http.ResponseWriter, r *http.Request) {24http.Redirect(w, r, "/about", http.StatusMovedPermanently)25})26siteMux.Get(reverse.Add("statistics", "/statistika"), handlers.StatisticsAction(app))27siteMux.Get("/robots.txt", handlers.RobotsTXTAction)28siteMux.Get("/humans.txt", handlers.HumansTXTAction)29siteMux.Get("/favicon.ico", handlers.FavIconAction)30siteMux.Get("/headers", handlers.HeadersDebug)31siteMux.Get("/sitemap.xml", handlers.SitemapAction(app))32siteMux.Get(reverse.Add("feed-atom", "/feed/atom"), handlers.FeedAction(app, models.AtomFeedType))33siteMux.Get(reverse.Add("feed-rss", "/feed/rss"), handlers.FeedAction(app, models.RssFeedType))34siteMux.Post(reverse.Add("add-comment-dummy", "/add-comment"), handlers.AddCommentDummy)35siteMux.Post(reverse.Add("add-comment", "/add-ajax-comment"), handlers.AddComment(app))36siteMux.Post("/purge-cache", handlers.PurgeCache(app))37siteMux.Get("/images/avatar/{hash:[0-9A-Z]+}.png", handlers.AvatarGenerator(app))38siteMux.Get("/images/avatar/{hash:[0-9A-Z]+}.w{size:[0-9]+}.png", handlers.AvatarGeneratorWithSize(app))39siteMux.Get(reverse.Add("profile", "/profile"), handlers.ProfileAction(app))40siteMux.Post("/profile", handlers.UpdateProfile(app))41siteMux.Get("/email-unsubscribe/{hash:[0-9A-Z]+}", handlers.EmailUnsubscribe(app))42siteMux.Post("/email-unsubscribe/{hash:[0-9A-Z]+}", handlers.EmailUnsubscribePost(app))43siteMux.Get(reverse.Add("login", "/login"), handlers.LoginAction(app))44siteMux.Post("/login", handlers.LoginCheck(app))45siteMux.Get(reverse.Add("logout", "/logout"), handlers.LogoutAction)46
47oauthMux := chi.NewRouter()48siteMux.Mount(reverse.Group("oauth", "/oauth"), oauthMux)49
50oauthMux.Get(reverse.AddGr("oauth-authorize", "oauth", "/authorize/{provider}"), handlers.OAuthLogin(app))51oauthMux.Get(reverse.AddGr("oauth-verification", "oauth", "/verification/{provider}"), handlers.OAuthCallback(app))52oauthMux.Get(reverse.AddGr("oauth-check", "oauth", "/check/{request_id}"), handlers.OAuthCheckState(app))53
54fragmentsMux := chi.NewRouter()55siteMux.Mount(reverse.Group("fragments", "/_fragment"), fragmentsMux)56
57fragmentsMux.Get(reverse.AddGr("fragment-categories", "fragments", "/categories"), handlers.CategoriesFragment(app))58fragmentsMux.Get(reverse.AddGr("fragment-comments",59"fragments",60"/comments/{article_id:[0-9]+}/{disabled_flag:(?:e|d)}/{last_time:[0-9]+}"),61handlers.CommentsFragment(app),62)63fragmentsMux.Get(reverse.AddGr("fragment-recent-posts",64"fragments",65"/recent-posts/{article_id:[0-9]+}"),66handlers.RecentPostsFragment(app),67)68fragmentsMux.Get(reverse.AddGr("fragment-war", "fragments", "/war-in-ukraine"), handlers.DaysOfWarCounter)69fragmentsMux.Get(reverse.AddGr("auth-navigation", "fragments", "/auth-navigation"), handlers.AuthNavigation(app))70fragmentsMux.Get(reverse.AddGr("fragment-markdown", "fragments", "/markdown/{filename}"), handlers.MarkdownAction(app))71fragmentsMux.Get(reverse.AddGr("menu-auth", "fragments", "/menu-auth"), handlers.MenuAuth(app))72
73return siteMux74}
75