Last active
September 19, 2017 15:25
-
-
Save nire0510/5964566 to your computer and use it in GitHub Desktop.
[Configration Manager] 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 #javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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]; | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment