-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.go
38 lines (30 loc) · 1.2 KB
/
router.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
package main
import (
"fmt"
"net/http"
"os"
"github.com/Robinnnnn/good-vibes-only-server.git/utils"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
)
func initializeRouter(s *spotifyController) http.Handler {
router := mux.NewRouter()
// Standard app routes
router.HandleFunc("/alive", handleHealthcheck)
// Spotify routes
router.HandleFunc("/login", s.handleLogin).Methods("GET").Queries("playlistId", "{playlistId}")
router.HandleFunc("/login", s.handleLogin).Methods("GET")
router.HandleFunc("/oauth", s.handleOAuthRedirect).Methods("GET").Queries("code", "{code}", "state", "{state}")
router.HandleFunc("/refresh", s.handleTokenRefresh).Methods("POST")
routerWithLogs := handlers.LoggingHandler(os.Stdout, router)
routerWithCORS := handlers.CORS(
handlers.AllowedOrigins([]string{s.appConfig.WebBaseURL, s.appConfig.BaseURL}),
handlers.AllowedMethods([]string{http.MethodGet, http.MethodPost, http.MethodPut, http.MethodOptions}),
handlers.AllowedHeaders([]string{"X-Requested-With", "Content-Type", "Authorization"}),
)(routerWithLogs)
return routerWithCORS
}
func handleHealthcheck(w http.ResponseWriter, r *http.Request) {
fmt.Println("💙")
utils.RespondWithBody(w, "ok")
}