Skip to content

Commit

Permalink
Pull API key from environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffreyCA committed Aug 28, 2020
1 parent af92d4c commit d2a8064
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
API_KEY=<Last.fm API key>
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ yarn-debug.log*
yarn-error.log*

# local env files
.env
.env.local
.env.development.local
.env.test.local
Expand Down
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
# Last.fm Recently Played README
Show off your recent Last.fm scrobbles on your GitHub profile README! Powered by [Vercel](https://vercel.com).
Show off your recent Last.fm scrobbles on your GitHub profile README. Powered by [Vercel](https://vercel.com).

## Getting Started
Just add the following into your README and set the query parameter `username` to your Last.fm username.

```md
![JeffreyCA's scrobbles](https://lastfm-recently-played-readme.vercel.app/api?user=JeffreyCA01)
![JeffreyCA's scrobbles](https://lastfm-recently-played.vercel.app/api?user=JeffreyCA01)
```

### Custom track count
To a custom number of tracks, pass the query parameter `count` and set it to the number of tracks to display.

> Default: `5`
>
> Min: `1`
>
> Default: `5`
> Min: `1`
> Max: `10`
Example:
```md
![JeffreyCA's scrobbles](https://lastfm-recently-played-readme.vercel.app/api?user=JeffreyCA01&count=1)
![JeffreyCA's scrobbles](https://lastfm-recently-played.vercel.app/api?user=JeffreyCA01&count=1)
```

### Custom card width
To set a custom card width, pass the query parameter `width` and set it to the desired width in px.

> Default: `400`
>
> Min: `300`
>
> Default: `400`
> Min: `300`
> Max: `1000`
Example:
```md
![JeffreyCA's scrobbles](https://lastfm-recently-played-readme.vercel.app/api?user=JeffreyCA01&width=1000)
![JeffreyCA's scrobbles](https://lastfm-recently-played.vercel.app/api?user=JeffreyCA01&width=1000)
```

## Deploying own Vercel project

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/import/git?s=https%3A%2F%2Fgithub.com%2FJeffreyCA%2Flastfm-recently-played-readme&env=VERCEL_URL)

Deploy your own Vercel project using the link above. Next, you'll need to set the `API_KEY` environment variable to your Last.fm API key. The `VERCEL_URL` system environment variable should also be set in the Vercel project settings.

## Running locally
1. Install Node dependencies
```sh
Expand Down
5 changes: 3 additions & 2 deletions pages/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import axios from 'axios';
import { NextApiRequest, NextApiResponse } from 'next';
import { RecentTracksResponse } from '../../models/RecentTracksResponse';
import { BaseUrl, LastFmApiKey } from '../../settings';
import { generateSvg } from '../../utils/SvgUtil';

const defaultCount = 5;
Expand All @@ -12,6 +11,8 @@ const defaultWidth = 400;
const minWidth = 300;
const maxWidth = 1000;

const BaseUrl = process.env.VERCEL_URL ? `https://${process.env.VERCEL_URL}` : 'http://localhost:3000';

export default async (req: NextApiRequest, res: NextApiResponse): Promise<void> => {
const { user } = req.query;
if (!user) {
Expand Down Expand Up @@ -57,7 +58,7 @@ export default async (req: NextApiRequest, res: NextApiResponse): Promise<void>
params: {
user: user,
limit: count,
api_key: LastFmApiKey,
api_key: process.env.API_KEY,
format: 'json',
},
}
Expand Down
2 changes: 0 additions & 2 deletions settings.ts

This file was deleted.

1 comment on commit d2a8064

@vercel
Copy link

@vercel vercel bot commented on d2a8064 Aug 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.