From 05b9792d3f007177712ce080fad66031a4d9bd36 Mon Sep 17 00:00:00 2001 From: vrde Date: Wed, 10 Jun 2015 17:28:36 +0200 Subject: [PATCH] Add some new constants to the app --- gulpfile.js | 12 +++++++++--- index.html | 3 +++ js/app.js | 17 +++++++++++------ js/constants/application_constants.js | 2 +- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 9672721e..78d2df7c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -27,7 +27,6 @@ var uglify = require('gulp-uglify'); var config = { - baseUrl: (function () { var baseUrl = process.env.ONION_BASE_URL || '/'; return baseUrl + (baseUrl.match(/\/$/) ? '' : '/'); })(), bootstrapDir: './node_modules/bootstrap-sass', jestOptions: { rootDir: 'js', @@ -49,6 +48,13 @@ var config = { } }; +var constants = { + BASE_URL: (function () { var baseUrl = process.env.ONION_BASE_URL || '/'; return baseUrl + (baseUrl.match(/\/$/) ? '' : '/'); })(), + API_ENDPOINT: process.env.ONION_API_ENDPOINT || 'http://staging.ascribe.io/api/', + DEBUG: !argv.production, + CREDENTIALS: 'ZGltaUBtYWlsaW5hdG9yLmNvbTowMDAwMDAwMDAw' // dimi@mailinator:0000000000 +}; + gulp.task('build', ['js:build', 'sass:build', 'copy'], function() { }); @@ -85,7 +91,7 @@ gulp.task('browser-sync', function() { gulp.task('sass:build', function () { gulp.src('./sass/**/main.scss') - .pipe(template({BASE_URL: config.baseUrl})) + .pipe(template(constants)) .pipe(gulpif(!argv.production, sourcemaps.init())) .pipe(sass({ includePaths: [ @@ -115,7 +121,7 @@ gulp.task('copy', function () { .pipe(gulp.dest('./build/fonts')); gulp.src('./index.html') - .pipe(template({BASE_URL: config.baseUrl})) + .pipe(template(constants)) .pipe(gulp.dest('./build')); }); diff --git a/index.html b/index.html index 84d3787e..7c760b4a 100644 --- a/index.html +++ b/index.html @@ -9,6 +9,9 @@ diff --git a/js/app.js b/js/app.js index af92c379..447ecc96 100644 --- a/js/app.js +++ b/js/app.js @@ -6,19 +6,24 @@ import promise from 'es6-promise'; promise.polyfill(); -import AppConstants from './constants/application_constants'; import ApiUrls from './constants/api_urls'; import routes from './routes'; import fetch from './utils/fetch'; +let headers = { + 'Accept': 'application/json', + 'Content-Type': 'application/json' +}; + +if (window.DEBUG) { + headers.Authorization = 'Basic ' + window.CREDENTIALS; +} + fetch.defaults({ urlMap: ApiUrls, http: { - headers: { - 'Authorization': 'Basic ' + AppConstants.debugCredentialBase64, - 'Accept': 'application/json', - 'Content-Type': 'application/json' - } + headers: headers, + credentials: 'same-origin' }, fatalErrorHandler: (err) => { console.log(err); diff --git a/js/constants/application_constants.js b/js/constants/application_constants.js index 3db77698..161bdff0 100644 --- a/js/constants/application_constants.js +++ b/js/constants/application_constants.js @@ -6,7 +6,7 @@ let constants = { //FIXME: referring to a global variable in `window` is not // super pro. What if we render stuff on the server? 'baseUrl': window.BASE_URL, - 'apiEndpoint': 'http://staging.ascribe.io/api/', + 'apiEndpoint': window.API_ENDPOINT, 'debugCredentialBase64': 'ZGltaUBtYWlsaW5hdG9yLmNvbTowMDAwMDAwMDAw', // dimi@mailinator:0000000000 'aclList': ['edit', 'consign', 'transfer', 'loan', 'share', 'download', 'view', 'delete', 'del_from_collection', 'add_to_collection'] };