Commit d3d7dd64 authored by Pedro Eduardo Trujillo's avatar Pedro Eduardo Trujillo
Browse files

Sustituye petición a /env por variables globales

En lugar de exponer una ruta '/env' para obtener desde el cliente los
valores de configuración del entorno de forma asíncrona, se pasan hacia
las plantillas pug y se exponen en el layout común como variables
globales.
Se refactoriza para eliminar la asincronía ahora innecesaria,
simplificando el uso de estos valores de forma directa.
parent d34d9149
Loading
Loading
Loading
Loading
+17 −19
Original line number Diff line number Diff line
@@ -18,31 +18,29 @@ function getLang(req) {
	return req && req.headers && req.headers['content-language'] || params.lang;
}

function onGeneralRequest(req, res) {
function getEnv(req) {

	res.render('index', {
	return {
		version: version,
		useBuilt: params.useBuilt,
		debug: params.debug,
		apiUrl: apiUrl,
		production: production,
		lang: getLang(req)
	});
	};
}

function onEnvRequest(_req, res) {
function onGeneralRequest(req, res) {

	res.send({
		version: version,
		useBuilt: params.useBuilt,
		debug: params.debug,
		apiUrl: apiUrl,
		production: production
	res.render('index', {
		env: getEnv(req)
	});
}

function onActivateAccountRequest(req, res) {

	res.render('activateAccount', {
		useBuilt: params.useBuilt,
		lang: getLang(req),
		apiUrl: apiUrl,
		env: getEnv(req),
		token: req.params.token
	});
}
@@ -50,15 +48,16 @@ function onActivateAccountRequest(req, res) {
function onNoSupportBrowserRequest(req, res) {

	res.render('noSupportBrowser', {
		useBuilt: params.useBuilt,
		lang: getLang(req)
		env: getEnv(req)
	});
}

function on404Request(_req, res) {
function on404Request(req, res) {

	res.status(404);
	res.render('404', { useBuilt: params.useBuilt });
	res.render('404', {
		env: getEnv(req)
	});
}

function onOwnRequestResponse(bindParams, internalRes) {
@@ -233,8 +232,7 @@ function onOauthRequestError(originalRes, err) {

function exposeRoutes(app) {

	app.get('/env', onEnvRequest)
		.get('/activateAccount/:token', onActivateAccountRequest)
	app.get('/activateAccount/:token', onActivateAccountRequest)
		.get('/noSupportBrowser', onNoSupportBrowserRequest)
		.get('/404', on404Request)
		.get('/sitemap.xml', onSitemapRequest)
+7 −13
Original line number Diff line number Diff line
@@ -43,19 +43,13 @@ define([

			_onLoadReCaptcha = null;

			var envDfd = window.env;
			if (envDfd) {
				envDfd.then(lang.hitch(this, function(envData) {

					var siteKey = envData.production ? this._siteKey : this._siteKeyForDebug;
			var siteKey = envProduction === 'true' ? this._siteKey : this._siteKeyForDebug;

			this._instanceId = grecaptcha.render(this.node, {
				'sitekey': siteKey,
				'theme': this._theme,
				'callback': this.callback
			});
				}));
			}
		},

		_instanceWasCreated: function() {
+1 −31
Original line number Diff line number Diff line
@@ -6,7 +6,6 @@ define([
	, 'app/redmicConfig'
	, 'dojo/_base/declare'
	, 'dojo/_base/lang'
	, 'dojo/Deferred'
	, 'dojo/dom'
	, 'dojo/dom-attr'
	, 'dojo/has'
@@ -32,7 +31,6 @@ define([
	, redmicConfig
	, declare
	, lang
	, Deferred
	, dom
	, domAttr
	, has
@@ -74,8 +72,6 @@ define([
			}
		};

	getGlobalContext().env = new Deferred();

	if (!CheckBrowser.isSupported()) {
		hideNativeLoadingNode();
		getGlobalContext().location.href = '/noSupportBrowser';
@@ -83,7 +79,7 @@ define([
		return;
	}

	return declare([_Module, _Store], {
	return declare(_Module, {
		//	summary:
		//		Módulo encargado de controlar el acceso a la aplicación.
		//	description:
@@ -134,7 +130,6 @@ define([
					HOME: 'home',
					LOGIN: 'login'
				},
				target: '/env',
				_reconnectTimeout: 10000
			};

@@ -220,8 +215,6 @@ define([

		postCreate: function() {

			this._getEnv();

			this._emitEvt('GET_CREDENTIALS');

			this.inherited(arguments);
@@ -333,29 +326,6 @@ define([
			this._onRouteChange();
		},

		_getEnv: function() {

			var envDfd = getGlobalContext().env;

			if (envDfd && !envDfd.isFulfilled()) {
				this._emitEvt('GET', {
					target: this.target
				});
			}
		},

		_itemAvailable: function(res) {

			var envDfd = getGlobalContext().env;
			envDfd.resolve(res.data);
		},

		_errorAvailable: function(error, status, resWrapper) {

			var envDfd = getGlobalContext().env;
			envDfd.reject(error);
		},

		_subCredentialsRemoved: function() {

			delete this._userFound;
+6 −16
Original line number Diff line number Diff line
@@ -54,21 +54,11 @@ define([

			this._checkPathVariableId();

			var envDfd = window.env;
			if (!envDfd) {
				return;
			}

			envDfd.then(lang.hitch(this, function(envData) {

				this._envData = envData;

			this._emitEvt('GET', {
				target: this.target,
				requesterId: this.ownChannel,
				id: this.pathVariableId
			});
			}));
		},

		_itemAvailable: function(item) {
@@ -81,7 +71,7 @@ define([
			}

			var pdfUrlProto = documentInternalUrl.replace('/api', redmicConfig.apiUrlVariable),
				pdfUrl = redmicConfig.getServiceUrl(pdfUrlProto, this._envData),
				pdfUrl = redmicConfig.getServiceUrl(pdfUrlProto),
				widgetInstance = this._getWidgetInstance('pdf');

			var callback = lang.hitch(this, this._loadPdfInWidget, pdfUrl);
+3 −7
Original line number Diff line number Diff line
@@ -573,27 +573,23 @@ define([], function() {
		return this.outerPaths.indexOf(ancestorPath) !== -1;
	};

	retObj.getServiceUrl = function(serviceName, envData) {
	retObj.getServiceUrl = function(serviceName) {

		if (!serviceName || !serviceName.length) {
			return;
		}

		if (!envData || !envData.apiUrl) {
			return serviceName;
		}

		// TODO esto es necesario hasta que todos los lang.replace de rutas se centralicen y se puedan devolver como dfd
		var undefinedIndex = serviceName.indexOf('undefined');
		if (undefinedIndex !== -1) {
			console.error('Service URL "%s" contains "undefined", variable replacement went wrong', serviceName);
			if (undefinedIndex === 0) {
				console.error('Trying to replace "undefined" with API URL..');
				return serviceName.replace('undefined', envData.apiUrl);
				return serviceName.replace('undefined', envApiUrl);
			}
		}

		return serviceName.replace('{apiUrl}', envData.apiUrl);
		return serviceName.replace('{apiUrl}', envApiUrl);
	};

	return retObj;
Loading