0

我有一个从 angular-fullstack yeoman 生成器生成的 angular fullstack 应用程序,并且在我的浏览器控制台中出现以下错误 -

Uncaught SyntaxError: Unexpected token e angular.js:1072

SyntaxError: Unexpected token e
    at Object.parse (native)
    at Object.fromJson (http://localhost:9000/src/vendor/angular/angular.js:1072:14)
    at Object.get (http://localhost:9000/src/vendor/angular/angular-cookies/angular-cookies.js:172:34)
    at request (http://localhost:9000/src/js/app.js:142:30)
    at processQueue (http://localhost:9000/src/vendor/angular/angular.js:13248:27)
    at http://localhost:9000/src/vendor/angular/angular.js:13264:27
    at Scope.$eval (http://localhost:9000/src/vendor/angular/angular.js:14466:28)
    at Scope.$digest (http://localhost:9000/src/vendor/angular/angular.js:14282:31) 
at angular.js:11655

所以,我明白app.js/142.30了,这是我的 app.js

'use strict';

angular.module('app', [
    'ngAnimate',
    'ngCookies',
    'ngResource',
    'ngSanitize',
    'ngTouch',
    'ngStorage',
    'ui.router',
    'ui.bootstrap',
    'ui.load',
    'ui.jq',
    'ui.validate',
    'oc.lazyLoad',
    'pascalprecht.translate',
    'infinite-scroll',
    'toaster',
    'wysiwyg.module',
    'ngTagsInput'
]).config(
    ['$stateProvider', '$urlRouterProvider','$locationProvider','$httpProvider',
        function ($stateProvider, $urlRouterProvider,$locationProvider, $httpProvider) {

            $urlRouterProvider
                .otherwise('/app/query/inbox/');
            $stateProvider
                .state('app', {
                    abstract: true,
                    url: '/app',
                    templateUrl: '/src/tpl/app.html',
                    resolve: {
                        deps: ['uiLoad',
                            function (uiLoad) {
                                return uiLoad.load(['/src/js/app/header/header.js']);
                            }]
                    }
                })
                .state('app.dashboard-v1', {
                    url: '/dashboard-v1',
                    templateUrl: '/src/tpl/app_dashboard_v1.html',
                    resolve: {
                        deps: ['$ocLazyLoad',
                            function ($ocLazyLoad) {
                                return $ocLazyLoad.load(['/src/js/controllers/chart.js']);
                            }]
                    }
                })
                .state('access', {
                    url: '/access',
                    template: '<div ui-view class="fade-in-right-big smooth"></div>'
                })
                .state('access.signin', {
                    url: '/signin',
                    templateUrl: '/src/tpl/page_signin.html',
                    resolve: {
                        deps: ['uiLoad',
                            function (uiLoad) {
                                return uiLoad.load(['/src/js/controllers/signin.js']);
                            }]
                    }
                })
                .state('access.signup', {
                    url: '/signup',
                    templateUrl: '/src/tpl/page_signup.html',
                    resolve: {
                        deps: ['uiLoad',
                            function (uiLoad) {
                                return uiLoad.load(['/src/js/controllers/signup.js']);
                            }]
                    }
                })
                .state('access.forgotpwd', {
                    url: '/forgotpwd',
                    templateUrl: '/src/tpl/page_forgotpwd.html'
                })
                .state('access.404', {
                    url: '/404',
                    templateUrl: '/src/tpl/page_404.html'
                })

                // circle
                .state('app.circle',{
                    abstract: true,
                    url: '/circle',
                    templateUrl: '/src/tpl/circle.html',
                    resolve: {
                        deps: ['uiLoad',
                            function (uiLoad) {
                                return uiLoad.load(['/src/js/app/circle/circle.js',
                                    '/src/vendor/libs/moment.min.js']);
                            }]
                    }
                })
                .state('app.circle.compose', {
                    url: '/{fold}/compose',
                    templateUrl: '/src/tpl/circle.new.html'
                })
                .state('app.circle.category', {
                    url: '/{fold}/category/{category}',
                    templateUrl: '/src/tpl/circle.list.category.html'
                })
                .state('app.circle.list', {
                    url: '/{fold}',
                    templateUrl: '/src/tpl/circle.list.html'
                })
                .state('app.query', {
                    abstract: true,
                    url: '/query',
                    templateUrl: '/src/tpl/mail.html',
                    // use resolve to load other dependences
                    resolve: {
                        deps: ['uiLoad',
                            function (uiLoad) {
                                return uiLoad.load(['/src/js/app/mail/mail.js',
                                    '/src/js/app/mail/mail-service.js',
                                    '/src/vendor/libs/moment.min.js']);
                            }]
                    }
                })
                .state('app.query.compose', {
                    url: '/compose',
                    templateUrl: '/src/tpl/mail.new.html'
                })
                .state('app.query.list', {
                    url: '/inbox/{fold}',
                    templateUrl: '/src/tpl/mail.list.html'
                })
                .state('app.query.detail', {
                    url: '/{queryId}',
                    templateUrl: '/src/tpl/mail.detail.html'
                });
            $locationProvider.html5Mode(true).hashPrefix('!');
            $httpProvider.interceptors.push('authInterceptor');
        }
    ])
  .factory('authInterceptor', function ($rootScope, $q, $cookieStore) {
    return {
      // Add authorization token to headers
      request: function (config) {
        config.headers = config.headers || {};
        if ($cookieStore.get('token')) {
          config.headers.Authorization = 'Bearer ' + $cookieStore.get('token');
        }
        return config;
      },

      // Intercept 401s and redirect you to login
      responseError: function (response) {
        if (response.status === 401) {
          $cookieStore.remove('token');
          return $q.reject(response);
        }
        else if (response.status === 403) {
          $cookieStore.remove('token');
          return $q.reject(response);
        } else if (response.status === 405) {
          $cookieStore.remove('token');
          return $q.reject(response);
        }
        else {
          return $q.reject(response);
        }
      }
    };
}).run(function ($state, $rootScope, $location, Auth) {
        // Redirect to login if route requires auth and you're not logged in
        $rootScope.$on('$stateChangeStart', function (event, toState) {
            var isNavigatingState = toState.name === 'access.signin';
            Auth.isLoggedInAsync(function (loggedIn) {
                if (!loggedIn) {
                    if(isNavigatingState) return;
                    else {
                        $state.go('access.signin');
                        event.preventDefault();
                    }
                }
            });
        });
    });

angular.module('app').factory('Discussion', function($resource) {
    return $resource('/api/discussion/:id',{id:'@_id'},{
        addBookmark:{
            method: 'POST',
            url: '/api/discussion/:id/bookmark/:queryId'
        },
        addLabel: {
            method: 'POST',
            url: '/api/discussion/:id/label/:label'
        },
        addCircle: {
            method: 'POST',
            url: '/api/discussion/:id/circle/:circle'
        }
    }); // Note the full endpoint address for discussion
});
angular.module('app').factory('Query', function($resource) {
    return $resource('/api/query/:id',{id:'@_id'},{
        addComment:{
            method: 'POST',
            url: '/api/query/:id/comment/:commentId',
        },
        addAnswer: {
            method: 'POST',
            url: '/api/query/:id/answer/:answerId'
        },
        addCommentInAnswer: {
            method: 'POST',
            url: '/api/query/:id/answer/:answerId/comment/:commentId'
        },
        acceptAnswer: {
            method: 'POST',
            url: '/api/query/:id/answer/accept/:answerId'
        },
        postInCircle: {
            method: 'POST',
            url: '/api/circle/:id/query/create'
        }
    }); // Note the full endpoint address for query
});
angular.module('app').factory('Comment', function($resource) {
    return $resource('/api/comment/:id'); // Note the full endpoint address for query
});
angular.module('app').factory('Reply', function($resource) {
    return $resource('/api/reply/:id'); // Note the full endpoint address for query
});
angular.module('app').factory('Answer', function($resource) {
    return $resource('/api/queryAnswer/:id',{id:'@_id'}); // Note the full endpoint address for query
});
angular.module('app').factory('Circle', function($resource) {
    return $resource('/api/circle/:id',{id:'@_id'},{
        addCategory: {
            method: 'POST',
            url: '/api/circle/:id/category/add/:categoryText'
        },
        getFeed:{
            method: 'GET',
            url: '/api/circle/:id/query',
            isArray: true
        }
    }); // Note the full endpoint address for query
});
angular.module('app').factory('Tag', function($resource) {
    return $resource('/api/tag/:id'); // Note the full endpoint address for query
});

app.js/142.30的是

if ($cookieStore.get('token')) {
          config.headers.Authorization = 'Bearer ' + $cookieStore.get('token');
        }

所以,我认为这是一些服务器端错误,cookiestore 没有被发送。那么,有人可以建议如何调试此错误或修复它吗?

[#UPDATE 服务器响应]

我已经在我的浏览器中向服务器发送了一个请求到这个 url

http://localhost:9000/api/query

把这个放进去response.body

UnauthorizedError: No authorization token was found
   at middleware (/home/hladdha/new_dashboard/node_modules/express-jwt/lib/index.js:80:21)
   at Middleware_Common_Object.compose.use.use.User.findOne._id (/home/hladdha/new_dashboard/server/auth/auth.service.js:24:13)
   at next (/home/hladdha/new_dashboard/node_modules/composable-middleware/lib/composable-middleware.js:59:18)
   at Middleware_Common_Object.middleware (/home/hladdha/new_dashboard/node_modules/composable-middleware/lib/composable-middleware.js:76:7)
   at middleware (/home/hladdha/new_dashboard/node_modules/composable-middleware/lib/composable-middleware.js:31:25)
   at Layer.handle [as handle_request] (/home/hladdha/new_dashboard/node_modules/express/lib/router/layer.js:82:5)
   at next (/home/hladdha/new_dashboard/node_modules/express/lib/router/route.js:100:13)
   at Route.dispatch (/home/hladdha/new_dashboard/node_modules/express/lib/router/route.js:81:3)
   at Layer.handle [as handle_request] (/home/hladdha/new_dashboard/node_modules/express/lib/router/layer.js:82:5)
   at /home/hladdha/new_dashboard/node_modules/express/lib/router/index.js:234:24
   at Function.proto.process_params (/home/hladdha/new_dashboard/node_modules/express/lib/router/index.js:312:12)
   at /home/hladdha/new_dashboard/node_modules/express/lib/router/index.js:228:12
   at Function.match_layer (/home/hladdha/new_dashboard/node_modules/express/lib/router/index.js:295:3)
   at next (/home/hladdha/new_dashboard/node_modules/express/lib/router/index.js:189:10)
   at /home/hladdha/new_dashboard/node_modules/express/lib/router/index.js:191:16
   at Function.match_layer (/home/hladdha/new_dashboard/node_modules/express/lib/router/index.js:295:3)

并将其放入response.cookie-

connect.sid=s%3AUVG1ZoniaFhD1zAi0lbU58imO9b6Q20h.PyE%2BjA7pVU8sQImtQIkBVSHOKfsYHzwBjLo4cWcGUhc; token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJfaWQiOiI1NjRhMjVkODUzOWU2ZmI5NGEzZmM4MjciLCJyb2xlIjoiYWRtaW4iLCJpYXQiOjE0NDc2OTk5MzksImV4cCI6MTQ0NzcxNzkzOX0.mEC7frWYFtm_evyhLRjAjulje4xNPKpxvlYtUTLhlH0; XSRF-TOKEN=4MecIMRd68uBnEtgASSi3pprY4fDR%2BxreRmkY%3D; sessionId=s%3A1BCHjpxw6ivMzf0lGKeKiiTLvt6P1IfT.jNCepQS%2Fwn3ERUndJLx60yODwkq5CBvLPiox6OVewks; mongo-express=s%3AQXlfcJ1lM_yTiMea31orKqPSIgf-49tP.SSTeCgWpkdgjs2T04hkAz9as3nvLFOHObhGDslLDxZI

我可以看到这不是不记名令牌 cookie,那么我该如何修复它?

4

0 回答 0