首页 文章

Juniper SSL VPN中的Angular Web应用程序路由

提问于
浏览
4

目前我正在使用AngularJS开发一个简单的Web应用程序 . 在开发过程中,我在IIS本地提供应用程序的同时对其进行了测试 . 但是,当我将它部署在公司Web服务器上并在Juniper SSL VPN中运行时,麻烦就开始了 .

首先,我必须应用以下'fix':AngularJS Routing Fails when running within a Juniper SSL VPN #8905

但上述修复只能解决部分问题 . 剩下的问题是,当我尝试从视图控制器加载除默认('/')视图($ location.path('/ anotherView')以外的其他视图时,AngularJS返回以下错误,我收到以下错误消息:

Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.3.15/$rootScope/infdig?p0=10&p1=%5B%5D
    at REGEX_STRING_REGEXP (,DanaInfo=server1.mydomain.nl,CT=js+angular.js:63)
    at Scope.$get.Scope.$digest (,DanaInfo=server1.mydomain.nl,CT=js+angular.js:14340)
    at Scope.$get.Scope.$apply (,DanaInfo=server1.mydomain.nl,CT=js+angular.js:14565)
    at done (,DanaInfo=server1.mydomain.nl,CT=js+angular.js:9685)
    at completeRequest (,DanaInfo=server1.mydomain.nl,CT=js+angular.js:9875)
    at XMLHttpRequest.requestLoaded (,DanaInfo=server1.mydomain.nl,CT=js+angular.js:9816)(anonymous function) @ ,DanaInfo=server1.mydomain.nl,CT=js+angular.js:11649$get @ ,DanaInfo=server1.mydomain.nl,CT=js+angular.js:8583$get.Scope.$apply @ ,DanaInfo=server1.mydomain.nl,CT=js+angular.js:14567done @ ,DanaInfo=server1.mydomain.nl,CT=js+angular.js:9685completeRequest @ ,DanaInfo=server1.mydomain.nl,CT=js+angular.js:9875requestLoaded @ ,DanaInfo=server1.mydomain.nl,CT=js+angular.js:9816

我用默认的AngularJS Routing和Angular ui.router机制对它进行了测试,两者都给出了相同的结果 .

任何帮助解决这个问题的人都非常感谢!

3 回答

  • 0

    通过将Juniper配置为反向代理来解决问题 .

  • 0

    我们通过在核心Angular.js代码库中修补parseAppUrl函数来解决这个问题,如下所示:

    function parseAppUrl(relativeUrl, locationObj, appBase) {
      var prefixed = (relativeUrl.charAt(0) !== '/');
      if (prefixed) {
        relativeUrl = '/' + relativeUrl;
      }
      var match = urlResolve(relativeUrl, appBase);
      locationObj.$$path = decodeURIComponent(prefixed && match.pathname.charAt(0) === '/' ?
          match.pathname.substring(1) : match.pathname);
      locationObj.$$search = parseKeyValue(match.search);
      locationObj.$$hash = decodeURIComponent(match.hash);
    
      //Detect Juniper re-write functions and handle the $$path issue
      if(locationObj.$$path === "[object Object]" && typeof(DanaOrigUrl) === 'function') {
        var __strH = 'href';
        var __tmpHack = match[__strH];
        var __nn = ("" + __tmpHack).match(/^(https?:\/\/[^\/]+)?([^?|#]*)/);
        locationObj.$$path = __nn[2];
      }
      // make sure path starts with '/';
      if (locationObj.$$path && locationObj.$$path.charAt(0) != '/') {
        locationObj.$$path = '/' + locationObj.$$path;
      }
    }
    

    参考:https://github.com/angular/angular.js/issues/8905

  • 2

    在我的情况下,我有重写URL的问题 . 网关使用标准的HTML href属性做得很好,但不适用于Angular AJAX调用 . 所以我写了一个拦截器来做这个伎俩:

    Angular 2 (JavaScript)

    app.config( function( $httpProvider ) {
      $httpProvider.interceptors.push( function( $q, $rootScope ) {
        return {
          'request': function( config ) {
            // Convert request URL for Juniper Secure Web Access
            if ( typeof DanaUrl === "function" && !config.url.includes( '.html' ) ) {
              config.url = DanaUrl( config.url );
            }
            return config;
          }
        };
      } );
    } );
    

    Angular 5+ (TypeScript)

    import { Injectable } from '@angular/core';
    import { HttpRequest, HttpHandler, HttpEvent, HttpInterceptor, HttpResponse, HttpErrorResponse, HttpHeaders } from '@angular/common/http';
    
    declare function DanaUrl(url: string): string;
    
    @Injectable()
    export class CustomHttpInterceptor implements HttpInterceptor {
    constructor(
    ) { }
    
    intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    
        // Rewrite Juniper SWA URLs
        if ( typeof DanaUrl === "function" && !request.url.includes( '.html' ) ) {
            request = request.clone({
                url: DanaUrl( request.url )
            });
        }
    
        return next.handle(request).do((event: HttpEvent<any>) => {
            if (event instanceof HttpResponse) {
                // do stuff with response if needed
            }
        }, (err: HttpErrorResponse) => {
    
        }).finally(() => {
    
        });
    }
    

    }

    如果Juniper的DanaURL功能可用且URL不包含“.html”,则URL将被重写 . 这是因为Angular使用URL将视图包含在模板中,甚至包括它们(例如在脚本标记中) . (我不喜欢这部分,但现在它正在工作......)

    我希望它对某些人有帮助......

相关问题