SuperPlan(13)Winner Seller Server - JSONP Basic Auth
SuperPlan(13)WinnerSellerServer-JSONPBasicAuth
15.BasicAuthonJSONPServer
Ifweareusingthebasicauth,wecandothejsonpclientlikethis.
HereistheViewControllerofBackbone.js
…snip...
render:function(){
window.logger.debug("IamgoingtohittheNavBarTemplatePage.");
varwidget=this;
varnavBars=newNavBarsModel();
window.logger.debug("navBarsurl="+navBars.url);
navBars.fetch({
data:{},
type:'GET',
success:function(data,response,options){
window.logger.debug("NavBarViewdata="+data);
varcompiledTemplate=_.template(htmlTemplate,{items:data});
$("#navBar").html(compiledTemplate);
},
error:function(jqXHR,textStatus,errorThrown){
window.logger.error('errorarguments:',arguments);
window.logger.error(jqXHR+""+textStatus+""+errorThrown);
},
complete:function(xhr,textStatus){
window.logger.debug(textStatus);
}
});
}
…snip…
HereistheModelLayerofBackbone.js
…snip...
varItems=Backbone.Collection.extend({
url:'/navbars',
parse:function(response){
window.logger.debug("gettingNavBarsfromresponse="+response);
returnresponse;
},
sync:function(method,model,options){
options.timeout=10000;
//jsonmock
//options.url='http://localhost:9000/data'+"/navbars"+".JSON";
//options.dataType='json';
//jsonp
options.dataType="jsonp";
options.crossDomain=true;
options.url='http://'+'customer'+':'+'customer'+'@'+'localhost:9002/v1/sillycat'+'/navbars';
returnBackbone.sync(method,model,options);
}
});
…snip…
Ittheserverside,wealsousejsonpwithParameter
…snip...
pathPrefix(Version/BrandCode){(apiVersion,brandCode)=>
authenticate(BasicAuth(newBrandUserPassAuthenticator(dao),"Realm")){user=>
path("products"){
jsonpWithParameter("callback"){
complete(HttpBody(`application/json`,
dao.db.withSession{
logger.debug("HittingtheURInavbarswithapiVersion="+apiVersion+",brandCode="+brandCode)
DefaultJsonProtocol.listFormat[NavBar].write(dao.NavBars.all).toString
}
))
}
}
}
}
…snip…
ItisnotniceandprettytousePOSTinjsonp.SoIwillchangebacktoJSONforboththeserversideandclientside.
16.JSONcrossdomain
comesoon...
17.Integration(Backbone+Require+Jasmine+Phantom+Grunt+Bootstrap)
comesoon…
References:
integration
http://hdnrnzk.me/2013/01/10/backbone-requirejs-jasmine-phantomjs-and-grunt/
https://github.com/ghiden/backbone-requirejs-jasmine-phantomjs-grunt-setup
superplan12