forked from getfider/fider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.go
134 lines (111 loc) · 5.2 KB
/
routes.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package main
import (
"time"
"github.com/getfider/fider/app/handlers"
"github.com/getfider/fider/app/middlewares"
"github.com/getfider/fider/app/models"
"github.com/getfider/fider/app/pkg/oauth"
"github.com/getfider/fider/app/pkg/web"
)
// GetMainEngine returns main HTTP engine
func GetMainEngine(settings *models.SystemSettings) *web.Engine {
r := web.New(settings)
r.Worker().Use(middlewares.WorkerSetup(r.Worker().Logger()))
r.Use(middlewares.Secure())
r.Use(middlewares.Compress())
assets := r.Group()
{
assets.Use(middlewares.ClientCache(365 * 24 * time.Hour))
assets.Static("/favicon.ico", "favicon.ico")
assets.Static("/assets/*filepath", "dist")
}
r.Use(middlewares.WebSetup(r.Logger()))
noTenant := r.Group()
{
noTenant.Post("/csp-report", handlers.CSPReport())
noTenant.Post("/api/tenants", handlers.CreateTenant())
noTenant.Get("/api/tenants/:subdomain/availability", handlers.CheckAvailability())
noTenant.Get("/signup", handlers.SignUp())
noTenant.Get("/oauth/facebook", handlers.SignInByOAuth(oauth.FacebookProvider))
noTenant.Get("/oauth/facebook/callback", handlers.OAuthCallback(oauth.FacebookProvider))
noTenant.Get("/oauth/google", handlers.SignInByOAuth(oauth.GoogleProvider))
noTenant.Get("/oauth/google/callback", handlers.OAuthCallback(oauth.GoogleProvider))
noTenant.Get("/oauth/github", handlers.SignInByOAuth(oauth.GitHubProvider))
noTenant.Get("/oauth/github/callback", handlers.OAuthCallback(oauth.GitHubProvider))
}
r.Use(middlewares.Tenant())
avatar := r.Group()
{
avatar.Use(middlewares.ClientCache(72 * time.Hour))
avatar.Get("/avatars/:size/:id/:name", handlers.Avatar())
}
open := r.Group()
{
open.Get("/signup/verify", handlers.VerifySignUpKey())
open.Use(middlewares.OnlyActiveTenants())
open.Get("/signin", handlers.SignInPage())
open.Get("/not-invited", handlers.NotInvitedPage())
open.Get("/signin/verify", handlers.VerifySignInKey(models.EmailVerificationKindSignIn))
open.Get("/invite/verify", handlers.VerifySignInKey(models.EmailVerificationKindUserInvitation))
open.Post("/api/signin/complete", handlers.CompleteSignInProfile())
open.Post("/api/signin", handlers.SignInByEmail())
}
r.Use(middlewares.JwtGetter())
r.Use(middlewares.JwtSetter())
page := r.Group()
{
page.Use(middlewares.OnlyActiveTenants())
page.Use(middlewares.CheckTenantPrivacy())
public := page.Group()
{
public.Get("/", handlers.Index())
public.Get("/api/ideas/search", handlers.SearchIdeas())
public.Get("/ideas/:number", handlers.IdeaDetails())
public.Get("/ideas/:number/*all", handlers.IdeaDetails())
public.Get("/signout", handlers.SignOut())
public.Get("/api/status", handlers.Status(settings))
}
private := page.Group()
{
private.Use(middlewares.IsAuthenticated())
private.Get("/settings", handlers.UserSettings())
private.Get("/notifications", handlers.Notifications())
private.Get("/notifications/:id", handlers.ReadNotification())
private.Get("/change-email/verify", handlers.VerifyChangeEmailKey())
private.Post("/api/ideas", handlers.PostIdea())
private.Post("/api/ideas/:number", handlers.UpdateIdea())
private.Post("/api/ideas/:number/comments", handlers.PostComment())
private.Post("/api/ideas/:number/comments/:id", handlers.UpdateComment())
private.Post("/api/ideas/:number/status", handlers.SetResponse())
private.Post("/api/ideas/:number/support", handlers.AddSupporter())
private.Post("/api/ideas/:number/unsupport", handlers.RemoveSupporter())
private.Post("/api/ideas/:number/subscribe", handlers.Subscribe())
private.Post("/api/ideas/:number/unsubscribe", handlers.Unsubscribe())
private.Post("/api/ideas/:number/tags/:slug", handlers.AssignTag())
private.Delete("/api/ideas/:number/tags/:slug", handlers.UnassignTag())
private.Post("/api/user/settings", handlers.UpdateUserSettings())
private.Post("/api/user/change-email", handlers.ChangeUserEmail())
private.Post("/api/notifications/read-all", handlers.ReadAllNotifications())
private.Get("/api/notifications/unread/total", handlers.TotalUnreadNotifications())
private.Use(middlewares.IsAuthorized(models.RoleCollaborator, models.RoleAdministrator))
private.Get("/admin", handlers.Page())
private.Get("/admin/privacy", handlers.Page())
private.Get("/admin/invitations", handlers.Page())
private.Get("/admin/members", handlers.ManageMembers())
private.Get("/admin/tags", handlers.ManageTags())
private.Post("/api/admin/invitations/send", handlers.SendInvites())
private.Post("/api/admin/invitations/sample", handlers.SendSampleInvite())
private.Use(middlewares.IsAuthorized(models.RoleAdministrator))
private.Get("/admin/export", handlers.Page())
private.Get("/admin/export/ideas.csv", handlers.ExportIdeasToCSV())
private.Delete("/api/ideas/:number", handlers.DeleteIdea())
private.Post("/api/admin/settings/general", handlers.UpdateSettings())
private.Post("/api/admin/settings/privacy", handlers.UpdatePrivacy())
private.Delete("/api/admin/tags/:slug", handlers.DeleteTag())
private.Post("/api/admin/tags/:slug", handlers.CreateEditTag())
private.Post("/api/admin/tags", handlers.CreateEditTag())
private.Post("/api/admin/users/:user_id/role", handlers.ChangeUserRole())
}
}
return r
}