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'); ...@@ -4,8 +4,6 @@ var xhr = require('xhr');
var jar = require('../lib/jar.js'); var jar = require('../lib/jar.js');
var log = require('../lib/log.js'); var log = require('../lib/log.js');
var CookieMixinFactory = require('./cookieMixinFactory.jsx');
/** /**
* Component mixin that constructs requests to the scratch api. * Component mixin that constructs requests to the scratch api.
* Custom arguments: * Custom arguments:
...@@ -15,10 +13,6 @@ var CookieMixinFactory = require('./cookieMixinFactory.jsx'); ...@@ -15,10 +13,6 @@ var CookieMixinFactory = require('./cookieMixinFactory.jsx');
* It also takes in other arguments specified in the xhr library spec. * It also takes in other arguments specified in the xhr library spec.
*/ */
var Api = { var Api = {
mixins: [
// Provides useScratchcsrftoken
CookieMixinFactory('scratchcsrftoken', '/csrf_token/')
],
api: function (opts, callback) { api: function (opts, callback) {
defaults(opts, { defaults(opts, {
host: window.env.API_HOST, host: window.env.API_HOST,
...@@ -57,7 +51,7 @@ var Api = { ...@@ -57,7 +51,7 @@ var Api = {
opts.headers['Accept-Language'] = jar.get('scratchlanguage') + ', en;q=0.8'; opts.headers['Accept-Language'] = jar.get('scratchlanguage') + ', en;q=0.8';
} }
if (opts.useCsrf) { 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); if (err) return log.error('Error while retrieving CSRF token', err);
opts.json.csrftoken = csrftoken; opts.json.csrftoken = csrftoken;
opts.headers['X-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