1 decade ago by FelipeBudinich
				With  this plugin you can validate the current hostname anywhere in your code calling ig.isCurrentDomainAllowed(); (it will return a boolean), like this:
Source code:
		
if (ig.isCurrentDomainAllowed()){
console.log('domain allowed');
} else {
console.log('domain not allowed');
}
Source code:
/*global ig*/
ig.module(
    'plugins.domain'
).requires().defines(function () {
    'use strict';
    var DomainUtils = {
            isCurrentDomainAllowed: function () {
                var allowed = ['127.0.0.1', 'www.example.com', 'example.com'],
                    isAllowed = false,
                    i;
                for (i = 0; i < allowed.length; i += 1) {
                    if (window.location.hostname === allowed[i]) {
                        isAllowed = true;
                    }
                }
                return isAllowed;
            }
        },
        methodName;
    function installFunction(name, fn) {
        if (ig[name]) {
            throw ("method " + name + "() already defined elsewhere.");
        }
        Object.defineProperty(ig, name, {
            value: fn
        });
    }
    for (methodName in DomainUtils) {
        if (DomainUtils.hasOwnProperty(methodName)) {
            installFunction(methodName, DomainUtils[methodName]);
        }
    }
});
			