-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.go
39 lines (27 loc) · 959 Bytes
/
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
package main
import (
"net/http"
"github.com/zenazn/goji"
"github.com/zenazn/goji/web"
"github.com/simon-whitehead/react-todo/handlers"
"github.com/simon-whitehead/react-todo/middleware"
)
func routeSetup() {
// Static files (including React code)
http.Handle("/app/bundle.js", http.StripPrefix("/app/", http.FileServer(http.Dir("app"))))
// Every route requires the database and a few services
goji.Use(middleware.Database)
goji.Use(middleware.UserService)
// Routes only allowed for authorized users
var authorizedArea = web.New()
authorizedArea.Use(middleware.Auth)
// Main page
authorizedArea.Get("/", handlers.HomeIndexGET)
// Anyone can access login and logout
goji.Get("/register", handlers.RegisterGET)
goji.Post("/register", handlers.RegisterPOST)
goji.Get("/login", handlers.LoginIndexGET)
goji.Post("/login", handlers.LoginIndexPOST)
goji.Get("/logout", handlers.LogoutIndexGET)
goji.Handle("/", authorizedArea)
}