From bd2be63341e7ed14af212457fb96d38ce6d8c1a1 Mon Sep 17 00:00:00 2001 From: vrde Date: Tue, 16 Jun 2015 19:28:21 +0200 Subject: [PATCH] Fix empty X-CSRFToken bug --- js/utils/requests.js | 5 ++++- server.js | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/js/utils/requests.js b/js/utils/requests.js index 1eee67ab..20e8ef65 100644 --- a/js/utils/requests.js +++ b/js/utils/requests.js @@ -76,7 +76,10 @@ class Requests { request(verb, url, options) { options = options || {}; let merged = this._merge(this.httpOptions, options); - this.httpOptions.headers['X-CSRFToken'] = getCookie('csrftoken'); + let csrftoken = getCookie('csrftoken'); + if (csrftoken) { + merged.headers['X-CSRFToken'] = csrftoken; + } merged.method = verb; return fetch(url, merged) .then(this.unpackResponse) diff --git a/server.js b/server.js index ef590a70..156b22f3 100644 --- a/server.js +++ b/server.js @@ -12,14 +12,19 @@ app.use(baseUrl + 'static/js', express.static(__dirname + '/build/js')); app.use(baseUrl + 'static/img', express.static(__dirname + '/build/img')); app.use(baseUrl + 'static/css', express.static(__dirname + '/build/css')); app.use(baseUrl + 'static/fonts', express.static(__dirname + '/build/fonts')); -app.use(baseUrl + 'static/thirdparty/', express.static(__dirname + '/node_modules')); +app.use(baseUrl + 'static/thirdparty', express.static(__dirname + '/node_modules')); app.get(/.*/, function(req, res) { + console.log('%s %s', req.method, req.path); res.sendFile(__dirname + '/build/index.html'); }); + if (require.main === module) { - app.listen(process.env.PORT || 4000); + var port = process.env.PORT || 4000; + console.log('Starting Onion server on port', port, + 'baseUrl is set to', baseUrl); + app.listen(port); } module.exports.app = app;