Same .me format for providers; CORS for Genius
This commit is contained in:
@ -27,16 +27,8 @@ var sendRequest = (dispatch, getState, endpoint, method = 'GET', data = false) =
|
||||
var config = {
|
||||
method: method,
|
||||
url: 'https://api.genius.com/'+endpoint+'?access_token='+getState().genius.access_token,
|
||||
dataType: 'jsonp',
|
||||
timeout: 30000,
|
||||
crossDomain: true,
|
||||
async: true,
|
||||
headers: {
|
||||
// We can't use headers as this seems to trigger CORS issues. Instead we have to post as URL params
|
||||
// Authorization: 'Bearer '+ getState().genius.access_token,
|
||||
Accept: 'application/json',
|
||||
"Access-Control-Allow-Origin": "*"
|
||||
}
|
||||
crossDomain: true
|
||||
}
|
||||
|
||||
// only if we've got data do we add it to the request (this prevents appending of "&false" to the URL)
|
||||
@ -113,13 +105,10 @@ export function getMe(){
|
||||
});
|
||||
},
|
||||
error => {
|
||||
console.log(error);
|
||||
/*
|
||||
dispatch(coreActions.handleException(
|
||||
'Could not load your Genius profile',
|
||||
error
|
||||
));
|
||||
*/
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
39
src/js/services/genius/middleware.js
Executable file
39
src/js/services/genius/middleware.js
Executable file
@ -0,0 +1,39 @@
|
||||
|
||||
var helpers = require('./../../helpers')
|
||||
var coreActions = require('../core/actions')
|
||||
|
||||
const GeniusMiddleware = (function(){
|
||||
return store => next => action => {
|
||||
var state = store.getState();
|
||||
|
||||
switch(action.type){
|
||||
|
||||
case 'GENIUS_ME_LOADED':
|
||||
store.dispatch({
|
||||
type: 'GENIUS_USER_LOADED',
|
||||
user: action.me
|
||||
});
|
||||
next(action);
|
||||
break;
|
||||
|
||||
case 'GENIUS_USER_LOADED':
|
||||
var user = Object.assign(
|
||||
{},
|
||||
action.user,
|
||||
{
|
||||
uri: "genius:user:"+action.user.id
|
||||
}
|
||||
);
|
||||
store.dispatch(coreActions.userLoaded(user));
|
||||
next(action);
|
||||
break;
|
||||
|
||||
|
||||
// This action is irrelevant to us, pass it on to the next middleware
|
||||
default:
|
||||
return next(action);
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
export default GeniusMiddleware
|
||||
Reference in New Issue
Block a user