diff --git a/app.js b/app.js index 5ea8eb4db..3abffd58d 100644 --- a/app.js +++ b/app.js @@ -4,7 +4,7 @@ const express = require('express'); const hbs = require('hbs'); // require spotify-web-api-node package here: - +const SpotifyWebApi = require('spotify-web-api-node'); const app = express(); app.set('view engine', 'hbs'); @@ -12,7 +12,42 @@ app.set('views', __dirname + '/views'); app.use(express.static(__dirname + '/public')); // setting the spotify-api goes here: +const spotifyApi = new SpotifyWebApi({ + clientId: process.env.CLIENT_ID, + clientSecret: process.env.CLIENT_SECRET + }); + + // Retrieve an access token + spotifyApi + .clientCredentialsGrant() + .then(data => spotifyApi.setAccessToken(data.body['access_token'])) + .catch(error => console.log('Something went wrong when retrieving an access token', error)); // Our routes go here: +app.get('/', (req, res) => { + res.render('index'); + }); + +app.get('/artist-search', (req, res) => { + spotifyApi + .searchArtists(req.query.artist) + .then(data => { + console.log('The received data from the API: ', data.body.artists.items); + res.render('artist-search-results', { artists: data.body.artists.items }); + }) + .catch(err => console.log('The error while searching artists occurred: ', err)); + } +); + +app.get('/albums/:artistId', (req, res) => { + spotifyApi + .getArtistAlbums(req.params.artistId) + .then(data => { + console.log('Artist albums', data.body.items); + res.render('albums', { albums: data.body.items }); + }) + .catch(err => console.log('The error while searching albums occurred: ', err)); + } +); app.listen(3000, () => console.log('My Spotify project running on port 3000 🎧 🥁 🎸 🔊')); diff --git a/package.json b/package.json index c9f4085ba..4aedf7a39 100644 --- a/package.json +++ b/package.json @@ -12,5 +12,11 @@ "license": "ISC", "devDependencies": { "nodemon": "^2.0.2" + }, + "dependencies": { + "dotenv": "^16.4.5", + "express": "^4.19.2", + "hbs": "^4.2.0", + "spotify-web-api-node": "^5.0.2" } } diff --git a/public/styles/style.css b/public/styles/style.css index e69de29bb..5348b16fd 100644 --- a/public/styles/style.css +++ b/public/styles/style.css @@ -0,0 +1,82 @@ +/* Reset default styles */ +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} + +/* Set background color */ +body { + background-color: #000; +} + +/* Set font and text color */ +body, h1, p { + font-family: Arial, sans-serif; + color: #fff; +} + +/* Set container styles */ +.container { + max-width: 1200px; + margin: 0 auto; + padding: 20px; +} + +/* Set header styles */ +.header { + text-align: center; + margin-bottom: 20px; +} + +.header h1 { + font-size: 36px; + margin-bottom: 10px; +} + +.header p { + font-size: 18px; +} + +/* Set navigation styles */ +.navbar { + display: flex; + justify-content: center; + margin-bottom: 20px; +} + +.navbar a { + margin: 0 10px; + text-decoration: none; + color: #fff; + font-size: 18px; +} + +/* Set main content styles */ +.main-content { + display: flex; + justify-content: center; + align-items: center; + height: 400px; +} + +.main-content h2 { + font-size: 24px; + margin-bottom: 10px; +} + +.main-content p { + font-size: 16px; +} + +/* Set footer styles */ +.footer { + text-align: center; + margin-top: 20px; +} + +.footer p { + font-size: 14px; +} + +/* Add additional styles as needed */ \ No newline at end of file diff --git a/views/albums.hbs b/views/albums.hbs new file mode 100644 index 000000000..1637d4a2c --- /dev/null +++ b/views/albums.hbs @@ -0,0 +1,8 @@ +{{#each albums}} +