Commit 1205ed01 authored by Ray Schamp's avatar Ray Schamp

Make Api mixin usable as a standalone module

parent faabc63e
......@@ -4,8 +4,6 @@ var xhr = require('xhr');
var jar = require('../lib/jar.js');
var log = require('../lib/log.js');
var CookieMixinFactory = require('./cookieMixinFactory.jsx');
/**
* Component mixin that constructs requests to the scratch api.
* Custom arguments:
......@@ -15,10 +13,6 @@ var CookieMixinFactory = require('./cookieMixinFactory.jsx');
* It also takes in other arguments specified in the xhr library spec.
*/
var Api = {
mixins: [
// Provides useScratchcsrftoken
CookieMixinFactory('scratchcsrftoken', '/csrf_token/')
],
api: function (opts, callback) {
defaults(opts, {
host: window.env.API_HOST,
......@@ -57,7 +51,7 @@ var Api = {
opts.headers['Accept-Language'] = jar.get('scratchlanguage') + ', en;q=0.8';
}
if (opts.useCsrf) {
this.useScratchcsrftoken(function (err, csrftoken) {
jar.use('scratchcsrftoken', '/csrf_token/', function (err, csrftoken) {
if (err) return log.error('Error while retrieving CSRF token', err);
opts.json.csrftoken = csrftoken;
opts.headers['X-CSRFToken'] = csrftoken;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment