-
Notifications
You must be signed in to change notification settings - Fork 2
/
routes.go
74 lines (59 loc) · 2.72 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
package main
import (
"time"
"github.com/willybeans/freedu_go/handlers"
"github.com/willybeans/freedu_go/logger"
"github.com/willybeans/freedu_go/websockets"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
"github.com/go-chi/cors"
)
func NewRouter() *chi.Mux {
router := chi.NewRouter()
// Middleware
//"github.com/rs/cors"
// router.Use(cors.Default().Handler)
router.Use(middleware.RequestID)
router.Use(middleware.RealIP)
router.Use(logger.RequestLogger)
// Basic CORS
// for more ideas, see: https://developer.github.com/v3/#cross-origin-resource-sharing
router.Use(cors.Handler(cors.Options{
// AllowedOrigins: []string{"https://foo.com"}, // Use this to allow specific origin hosts
AllowedOrigins: []string{"https://*", "http://*"},
// AllowOriginFunc: func(r *http.Request, origin string) bool { return true },
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"},
ExposedHeaders: []string{"Link"},
AllowCredentials: false,
MaxAge: 300, // Maximum value not ignored by any of major browsers
}))
// Set a timeout value on the request context (ctx), that will signal
// through ctx.Done() that the request has timed out and further
// processing should be stopped.
router.Use(middleware.Timeout(60 * time.Second))
router.Get("/healthcheck", handlers.Healthcheck)
router.Post("/image", handlers.ImageHandler)
router.Get("/scrape", handlers.ScrapeHandler)
router.Get("/getContent", handlers.GetContentHandler)
router.Get("/getAllContent", handlers.GetAllContentHandler)
router.Get("/getAllContentByQuery", handlers.GetAllContentByQueryHandler)
router.Get("/getAllUserContent", handlers.GetAllUserContentHandler)
router.Post("/newContent", handlers.NewContentHandler)
router.Put("/updateContent", handlers.UpdateContentHandler)
router.Delete("/deleteContent", handlers.DeleteContentHandler)
router.Get("/getUser", handlers.GetUserHandler)
router.Get("/getAllUsers", handlers.GetAllUsersHandler)
router.Get("/getAllUsersByQuery", handlers.GetAllUsersByQueryHandler)
router.Post("/newUser", handlers.NewUserHandler)
router.Put("/updateUser", handlers.UpdateUserHandler)
router.Delete("/deleteUser", handlers.DeleteUserHandler)
router.Get("/getMessagesByChatId", handlers.GetMessagesByChatIDHandler)
router.Get("/getAllChatsByUserId", handlers.GetAllChatsForUserHandler)
// combine with other req for users
router.Get("/getAllXRefForChat", handlers.GetAllXRefForChatHandler)
router.Post("/newChat", handlers.NewChatHandler)
router.Post("/newMessageForUserInChat", handlers.NewMessageForUserInChatHandler)
router.Handle("/ws", websockets.CreateWsConnection())
return router
}