{"id":15155522,"url":"https://github.com/baoopn/spotify-api","last_synced_at":"2026-01-21T16:32:21.060Z","repository":{"id":254531147,"uuid":"846491545","full_name":"baoopn/spotify-api","owner":"baoopn","description":"This repository contains an Express.js server that interacts with the Spotify API to securely fetch data such as currently playing tracks, recently played tracks, and song IDs. It includes essential middleware for CORS, rate limiting, timeouts, and referer checks to ensure safe and efficient API usage.","archived":false,"fork":false,"pushed_at":"2025-02-23T20:16:39.000Z","size":1661,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-23T21:23:16.610Z","etag":null,"topics":["express-js","rest-api","spotify-api"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/baoopn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-23T10:20:59.000Z","updated_at":"2025-02-23T20:16:27.000Z","dependencies_parsed_at":"2024-09-10T09:15:40.223Z","dependency_job_id":null,"html_url":"https://github.com/baoopn/spotify-api","commit_stats":{"total_commits":36,"total_committers":1,"mean_commits":36.0,"dds":0.0,"last_synced_commit":"74fff47988cbebe03481c86e7f84a47020d3e730"},"previous_names":["baoopn/spotify-api"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baoopn%2Fspotify-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baoopn%2Fspotify-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baoopn%2Fspotify-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baoopn%2Fspotify-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/baoopn","download_url":"https://codeload.github.com/baoopn/spotify-api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247653107,"owners_count":20973755,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["express-js","rest-api","spotify-api"],"created_at":"2024-09-26T18:23:05.144Z","updated_at":"2026-01-21T16:32:21.012Z","avatar_url":"https://github.com/baoopn.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Spotify Tokens API\n\nThis project provides an Express.js server that interacts with the Spotify API to fetch information about the currently playing track, recently played tracks, and song IDs. The use of an API server helps protect your secret tokens since frontend apps not built securely (e.g., with Create React App) may accidentally expose tokens in built JavaScript files. The server also serves a static webpage (HTML, CSS, JS) or a static build of a frontend framework (e.g., Create React App) at the root (`/`). It includes middleware for CORS, rate limiting, and request timeouts to ensure secure and efficient API usage.\n\n## Features\n\n- **CORS**: Cross-Origin Resource Sharing to control access to the API.\n- **Rate Limiting**: Limits the number of requests from a single IP to prevent abuse.\n- **Timeout**: Sets a timeout for API requests to avoid long-running requests.\n- **Referer Check**: Ensures that requests come from allowed origins.\n- **Endpoints**:\n  - `/`: Serves static webpage in static directory\n  - `/songid`: Fetches currently playing song's ID.\n  - `/currently-playing`: Fetches information about the currently playing track.\n  - `/recently-played`: Fetches information about recently played tracks.\n\n## Prerequisites\n\n- Node.js\n- npm (Node Package Manager)\n- Spotify Developer Account (for API credentials)\n\n## Installation\n\n1. Clone the repository:\n   ```sh\n   git clone https://github.com/baoopn/spotify-api.git\n   cd spotify-api\n   ```\n\n2. Install dependencies:\n   ```sh\n   npm install\n   ```\n\n3. Create a `.env` file in the root directory and add your Spotify API credentials:\n   ```env\n   CLIENT_ID=your_spotify_client_id\n   CLIENT_SECRET=your_spotify_client_secret\n   REFRESH_TOKEN=your_spotify_refresh_token\n   PORT=3000 # or any port\n   REFERER=http://your-allowed-referer.com\n   ALLOWED_ORIGIN=http://your-allowed-origin.com\n   ```\n\n## Usage\n\n1. Start the server:\n   ```sh\n   npm start\n   ```\n\n2. The server will be running at `http://localhost:3000`.\n\n## Endpoints\n\n### `/songid`\n\n- **Description**: Fetches song ID information.\n- **Method**: GET\n- **Middleware**: CORS, Rate Limiting, Timeout\n\n### `/currently-playing`\n\n- **Description**: Fetches information about the currently playing track.\n- **Method**: GET\n- **Middleware**: Referer Check, Rate Limiting, Timeout\n\n### `/recently-played`\n\n- **Description**: Fetches information about recently played tracks.\n- **Method**: GET\n- **Middleware**: Referer Check, Rate Limiting, Timeout\n\n## Middleware\n\n- **CORS**: Configured to allow requests from the specified origin.\n- **Rate Limiting**: Limits each IP to 240 requests per minute.\n- **Timeout**: Sets a 10-second timeout for API requests.\n- **Referer Check**: Ensures requests come from allowed referers.\n\n## Serving Static Files\n\nTo serve a static webpage (HTML, CSS, JS) or a static build of a framework like Create React App or Next.js at the root (`/`) of the API:\n\n1. Create a `static` directory in the root of your project:\n   ```sh\n   mkdir static\n   ```\n\n2. Place your static files (HTML, CSS, JS) or the static build of your framework inside the `static` directory.\n\n3. The server is already configured to serve static files from the `static` directory. When you navigate to `http://localhost:3000`, the static files will be served.\n\n## Docker\n\nTo install Docker Engine, follow the instructions in the official Docker documentation: [Install Docker Engine](https://docs.docker.com/engine/install/)\n\nFor more information and detailed documentation on Docker, visit the official Docker documentation: [Docker Documentation](https://docs.docker.com/)\n\n## Get Refresh Token\n\nRead the instructions for getting your Spotify's Refresh Token here [RefreshToken](RefreshToken.md)\n\n## Frontend\n\nFor reference, visit my [spotify-now-playing-react](https://github.com/baoopn/spotify-now-playing-react) repository.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n## Acknowledgements\n\n- [Express.js](https://expressjs.com/)\n- [dotenv](https://github.com/motdotla/dotenv)\n- [cors](https://github.com/expressjs/cors)\n- [express-rate-limit](https://github.com/nfriedly/express-rate-limit)\n- [connect-timeout](https://github.com/expressjs/timeout)\n- [axios](https://github.com/axios/axios)\n- [Spotify Web API](https://developer.spotify.com/documentation/web-api/)\n- [leerob's blog: Using the Spotify API with Next.js](https://leerob.io/blog/spotify-api-nextjs)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaoopn%2Fspotify-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbaoopn%2Fspotify-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaoopn%2Fspotify-api/lists"}