tangled
alpha
login
or
join now
tom.sherman.is
/
piper
0
fork
atom
A fork of https://github.com/teal-fm/piper
0
fork
atom
overview
issues
pulls
pipelines
fix build errors
Kyle Loveless
10 months ago
73e05427
d1440f61
+9
-7
3 changed files
expand all
collapse all
unified
split
.air.toml
cmd
main.go
routes.go
+1
-1
.air.toml
···
5
5
[build]
6
6
args_bin = []
7
7
bin = "./tmp/main"
8
8
-
cmd = "go build -o ./tmp/main ./cmd/main.go"
8
8
+
cmd = "go build -o ./tmp/main ./cmd"
9
9
delay = 1000
10
10
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
11
11
exclude_file = []
+2
-2
cmd/main.go
···
99
99
mbService: mbService,
100
100
spotifyService: spotifyService,
101
101
atprotoService: atprotoService,
102
102
-
} // MusicBrainz (public?)
102
102
+
}
103
103
104
104
trackerInterval := time.Duration(viper.GetInt("tracker.interval")) * time.Second
105
105
lastfmInterval := time.Duration(viper.GetInt("lastfm.interval_seconds")) * time.Second // Add config for Last.fm interval
···
117
117
serverAddr := fmt.Sprintf("%s:%s", viper.GetString("server.host"), viper.GetString("server.port"))
118
118
server := &http.Server{
119
119
Addr: serverAddr,
120
120
-
Handler: routes(app),
120
120
+
Handler: app.routes(),
121
121
IdleTimeout: time.Minute,
122
122
ReadTimeout: 5 * time.Second,
123
123
WriteTimeout: 10 * time.Second,
+6
-4
cmd/routes.go
···
3
3
import (
4
4
"net/http"
5
5
6
6
+
"github.com/justinas/alice"
6
7
"github.com/spf13/viper"
7
8
"github.com/teal-fm/piper/session"
8
9
)
9
10
10
10
-
func routes(app *application) http.Handler {
11
11
+
func (app *application) routes() http.Handler {
11
12
mux := http.NewServeMux()
12
13
13
14
mux.HandleFunc("/", session.WithPossibleAuth(home(app.database), app.sessionManager))
···
29
30
30
31
mux.HandleFunc("/api/v1/current-track", session.WithAPIAuth(apiCurrentTrack(app.spotifyService), app.sessionManager)) // Spotify Current
31
32
mux.HandleFunc("/api/v1/history", session.WithAPIAuth(apiTrackHistory(app.spotifyService), app.sessionManager)) // Spotify History
32
32
-
mux.HandleFunc("/api/v1/musicbrainz/search", apiMusicBrainzSearch(app.mbService))
33
33
+
mux.HandleFunc("/api/v1/musicbrainz/search", apiMusicBrainzSearch(app.mbService)) // MusicBrainz (public?)
33
34
34
35
serverUrlRoot := viper.GetString("server.root_url")
35
36
atpClientId := viper.GetString("atproto.client_id")
36
37
atpCallbackUrl := viper.GetString("atproto.callback_url")
37
37
-
http.HandleFunc("/.well-known/client-metadata.json", func(w http.ResponseWriter, r *http.Request) {
38
38
+
mux.HandleFunc("/.well-known/client-metadata.json", func(w http.ResponseWriter, r *http.Request) {
38
39
app.atprotoService.HandleClientMetadata(w, r, serverUrlRoot, atpClientId, atpCallbackUrl)
39
40
})
40
41
mux.HandleFunc("/oauth/jwks.json", app.atprotoService.HandleJwks)
41
42
42
42
-
return mux
43
43
+
standard := alice.New()
44
44
+
return standard.Then(mux)
43
45
}