66 "musicboxapi/configuration"
77 "musicboxapi/http"
88 "musicboxapi/logging"
9+ "os"
910
1011 "github.com/gin-contrib/cors"
1112 "github.com/gin-gonic/gin"
@@ -14,7 +15,6 @@ import (
1415
1516func main () {
1617 // If yt-dlp isn't installed yet, download and cache it for further use.
17- // todo test....
1818 go ytdlp .MustInstall (context .TODO (), nil )
1919
2020 configuration .LoadConfig ()
@@ -32,13 +32,29 @@ func main() {
3232 if configuration .Config .UseDevUrl {
3333 engine .Use (cors .Default ())
3434 logging .Warning ("CORS is enabled for all origins" )
35+ } else {
36+
37+ origin := os .Getenv ("CORS_ORIGIN" )
38+
39+ // Use Default cors
40+ if len (origin ) == 0 {
41+ engine .Use (cors .Default ())
42+ logging .Warning ("CORS is enabled for all origins" )
43+ } else {
44+ strictCors := cors .New (cors.Config {
45+ AllowAllOrigins : false ,
46+ AllowOrigins : []string {origin }, // move to env
47+ })
48+ engine .Use (strictCors )
49+ }
3550 }
3651
3752 apiv1Group := engine .Group (configuration .GetApiGroupUrl ("v1" ))
3853 apiv1Group .GET ("/songs" , http .FetchSongs )
3954 apiv1Group .GET ("/playlist" , http .FetchPlaylists )
4055 apiv1Group .GET ("/playlist/:playlistId" , http .FetchPlaylistSongs )
4156 apiv1Group .GET ("/play/:sourceId" , http .Play )
57+ apiv1Group .GET ("/tasklogs" , http .FetchTaskLogs )
4258
4359 apiv1Group .POST ("/playlist" , http .InsertPlaylist )
4460 apiv1Group .POST ("/playlistsong/:playlistId/:songId" , http .InsertPlaylistSong )
0 commit comments