nire0510
7/10/2013 - 8:48 AM

A simple yet very useful application configuration manager. Settings section - general application settings, encapsulated. Endpoints are no

A simple yet very useful application configuration manager. Settings section - general application settings, encapsulated. Endpoints are not accessible since they have to be read-only. Globals section - global variables, if you need any.

/*
 * Nir Elbaz
 * config.js - Configuration Manager file for website & web apps.
 * v.1.0
 */
var Application = Application || {};

Application.ConfigurationManager = (function() {
  // Application settings:
  var Settings = {
		AppName: "My App",
		Logo: "images/favicon.png",
		Environment: "Production",
		Version: 1.0,
		Endpoints: {
			Development: {
				api: 'api/'
			},
			Production: {
				api: 'http://www.mysite.com/api/'
			}
		}
	};

  // Application global variables:
	var Globals = {
    
	};

	return {
		Globals:Globals,

		// Get configuration key value:
		getValue: function (key) {
			// Do not allow extraction of the endpoint section:
			if (key == "Endpoints") return null;
			return Settings[key];
		},

		// Get endpoint key based on selected environment:
		getEndPoints: function (key) {
			return Settings.Endpoints[Settings.Environment][key];
		}
	}
})();