I really love to share. Especially something great and awesome (and what can beat greatness and awesomness of music?). So I came up with an idea of a microservice that asks Spotify Web API for what I am listening to right now and shows it on my website. What started as easy "just see current song" microservice now have Material Design, songs history, current user information, track progress and Listen Along function.
This post will show how to set up your own Music Microservice on your own server (yes, this is open-source project).
Technology That Should Be Installed
How Do I Run It
I recommend to run it behind another nginx reverse proxy with domain name and HTTPS enabled (because that's how I do it using Docker-Webserver).
You Don't Have Spotify Web Application
Create it, configure Redirect URI and go to the next step.
You Have Spotify Web Application
- Clone the repository to your server
- Copy .env to .env.production.local and change latter:
SPOTIFY_CLIENT_ID - Client ID from Spotify Developer Dashboard. SPOTIFY_CLIENT_SECRET - Client Secret from Spotify Developer Dashboard. SPOTIFY_REDIRECT_URI - should be the same as any of Redirect URIs in settings from Spotify Developer Dashboard. SPOTIFY_REDIRECT_ENDPOINT - should be the same as last part of $SPOTIFY_REDIRECT_URI, it better be random if you don't want other people to login. SPOTIFY_LOGIN_ENDPOINT - can be anything, but it better be random if you don't want other people to login LISTEN_ALONG_REDIRECT_URI - should be the same as any of Redirect URIs in settings from Spotify Developer Dashboard. BUT! Last part should always be /listen_along_redirect. SECRET_KEY - secret key used for encrypting session cookie, better make it long and random. TESTING - if we are testing the app, in production should be false. Anything other that false will turn on TESTING.
- Run this from root folder of the repository:
cd frontend && npm install && cd .. sudo ./scripts/production 80
You can provide 0 instead of 80 to listen on Unix domain socket music-nginx.sock that will be accessible through nginx volume.
After that when you go to https://example.com/api/your_login_endpoint you will be redirected to Spotify login page.
Voila, it should work as soon as you login.
- Listen Along feature (DONE)
- Send 304 Not Modified answer if songs did not change (DONE)
- 100% Tests Coverage (IN PROGRESS)
- Modular Architecture (IN PROGRESS)