A simple Whois server with a simple simple API and a front-end built with AngularJS.

app.js 3.0KB

    'use strict'; /** * @ngdoc overview * @name domainManagerApp * @description * # domainManagerApp * * Main module of the application. */ angular .module('WhoisAPI', ['ngRoute', 'ngSanitize', 'showdown', 'hljs', 'angularSpinner']) .config(['$routeProvider', '$httpProvider', function($routeProvider, $httpProvider) { // Configs //Enable cross domain calls $httpProvider.defaults.useXDomain = true; //Remove the header used to identify ajax call that would prevent CORS from working delete $httpProvider.defaults.headers.common['X-Requested-With']; // Routes $routeProvider .when('/', { templateUrl: 'views/lookup.html', controller: 'WhoisController' }) .when('/docs', { templateUrl: 'views/docs.html', controller: 'DocsController' }) .otherwise({ redirectTo: '/' }); }]) .controller('HeaderController', ['$scope', '$location', function ($scope, $location) { $scope.isActive = function (viewLocation) { return viewLocation === $location.path(); }; }]) .controller('WhoisController',['$scope', '$rootScope', 'CurrentLookup', 'usSpinnerService', function ($scope, $rootScope, CurrentLookup, usSpinnerService) { if(CurrentLookup.get() == "") { $scope.domain = ""; $scope.showResult = false; } else { $scope.domain = JSON.stringify(CurrentLookup.get(), null, 4); $scope.showResult = true; $scope.url = CurrentLookup.getUrl(); } $scope.lookup = function(){ usSpinnerService.spin('spinner-1'); CurrentLookup.domainLookup($scope.url) } $rootScope.$on('lookup:finished', function() { if(!$scope.$$phase) { $scope.$apply(function(){ $scope.domain = JSON.stringify(CurrentLookup.get(), null, 4); $scope.showResult = true }); } else { $scope.domain = JSON.stringify(CurrentLookup.get(), null, 4); $scope.showResult = true } usSpinnerService.stop('spinner-1'); }); }]) .controller('DocsController', ['$scope', '$window', function ($scope, $window) { }]) .service('CurrentLookup', [ '$rootScope', '$http', function($rootScope, $http) { var domain = ""; var lastUrl = "" this.domainLookup = function(url){ console.log("Starting Domain Lookup...") $http({ method: 'GET', url: 'http://whois.j1x.co/' + url }).success(function(data) { console.log("Domain Lookup Successfull") console.log(data) domain = data; lastUrl = url $rootScope.$broadcast('lookup:finished'); }); } this.get = function() { return domain; } this.getUrl = function() { return lastUrl; } }]) .directive('markdown', ['$showdown', function ($showdown) { return { restrict: 'A', link: function (scope, element, attrs) { var htmlText = $showdown.makeHtml(element.text()); element.html(htmlText); } }; }])