This file contains hidden or 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
| $.ajax ({ | |
| type: 'GET', | |
| dataType: 'jsonp', | |
| crossDomain: true, | |
| jsonp: 'json_callback', | |
| url: 'http://www.giantbomb.com/api/search/?format=jsonp&api_key=[YOUR_API_KEY]&query=batman' | |
| }).done(function(data) { | |
| alert("success:", data); | |
| }).fail(function() { | |
| alert("error"); |
This file contains hidden or 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
| var express = require('express'); | |
| var router = express.Router(); | |
| /* handle root angular route redirects */ | |
| router.get('/*', function(req, res, next){ | |
| var url = req.originalUrl; | |
| if (url.split('.').length > 1){ | |
| next(); | |
| } else { | |
| // handles angular urls. i.e. anything without a '.' in the url (so static files aren't handled) |
This file contains hidden or 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
| app.controller('LoginCtrl', ['$scope', '$http', '$location', 'authService', | |
| function ($scope, $http, $location, authService) { | |
| $scope.submit = function () { | |
| $http.post('/authenticate', this.form) | |
| .success(function (data, status, headers, config) { | |
| // save json web token in session storage | |
| authService.saveToken(data.token); |
This file contains hidden or 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
| app.factory('authInterceptor', ['$q', '$location', 'authService', function ($q, $location, authService) { | |
| return { | |
| request: function (config) { | |
| config.headers = config.headers || {}; | |
| if (authService.isAuthed()) { | |
| config.headers.Authorization = 'Bearer ' + authService.getToken(); | |
| } | |
| return config; | |
| }, | |
| response: function (response) { |
This file contains hidden or 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
| app.service('authService', ['$window', function ($window) { | |
| this.parseJwt = function (token) { | |
| if (token) { | |
| var base64Url = token.split('.')[1]; | |
| var base64 = base64Url.replace('-', '+').replace('_', '/'); | |
| return JSON.parse($window.atob(base64)); | |
| } else return {}; | |
| }; |
NewerOlder