-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
46 lines (40 loc) · 1.17 KB
/
main.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
package main
import (
fmt "fmt"
log "log"
http "net/http"
godotenv "github.com/joho/godotenv"
api "records/backend/api"
auth "records/backend/auth"
)
func main() {
err := godotenv.Load()
if err != nil {
log.Println("No .env file found")
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
_, err := auth.InitSpotifyClient(r)
if err != nil {
authenticator := auth.InitSpotifyAuth()
url := authenticator.AuthURL(auth.State)
http.Redirect(w, r, url, http.StatusTemporaryRedirect)
} else {
http.ServeFile(w, r, "./frontend/dist/index.html")
}
})
http.HandleFunc("/assets/", func(w http.ResponseWriter, r *http.Request) {
path := "./frontend/dist" + r.URL.Path
http.ServeFile(w, r, path)
})
http.HandleFunc("/redirect", api.CompleteAuthEndpoint)
http.HandleFunc("/authed", api.AuthedEndpoint)
http.HandleFunc("/albums", api.AlbumsEndpoint)
http.HandleFunc("/recommendations/", api.RecommendationEndpoint)
http.HandleFunc("/add_album/", api.AddAlbumEndpoint)
http.HandleFunc("/remove_album/", api.RemoveAlbumEndpoint)
fmt.Println("Ready to serve on :5006")
err = http.ListenAndServe(":5006", nil)
if err != nil {
log.Println(err)
}
}