-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
41 lines (33 loc) · 1001 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const express = require('express');
const request = require('request');
const cors = require('cors');
const app = express();
app.use(cors({
origin: 'http://localhost:4200',
optionsSuccessStatus: 200
}));
const distDir = __dirname + "/dist/";
app.use(express.static(distDir));
app.listen(process.env.PORT || 8000, () => {
console.log('Server started');
});
app.route('/api/authtoken').get((req, res) => {
const authOptions = {
url: 'https://accounts.spotify.com/api/token',
headers: {
'Authorization': 'Basic ' + (new Buffer('aeeec6d2a17b46008124e63cda6b9146' + ':' + '2ebf6f87c51a4e4495f14a4a09afd83f').toString('base64'))
},
form: {
grant_type: 'client_credentials'
},
json: true
};
request.post(authOptions, function (error, response, body) {
if (!error) {
console.log('sending access token');
res.send({authtoken: body.access_token});
} else {
console.log(`Oh crap, something went wrong: ${error}`)
}
});
});