【问题标题】:Grunt-connect-proxy redirect?Grunt-connect-proxy 重定向?
【发布时间】:2013-11-18 20:38:33
【问题描述】:

我有一个前端使用 AngularJS,后端使用 Java Spring 3 的应用程序。

所以当我运行 grunt-server 时,我使用 grunt-connect-proxy 从前端部分联系后端部分。

所以我的连接配置是这样的:

     connect: {
                proxies: [
                    {
                        context:'/mdp-web',
                        host: 'localhost',
                        port: 8080,
                        https: false,
                        changeOrigin: true
                    }
                ],
                options: {
                    port: 9000,
                    // Change this to '0.0.0.0' to access the server from outside.
                    hostname: 'localhost'
                },
                livereload: {
                    options: {
                        middleware: function (connect) {
                            return [
                                proxySnippet,
                                lrSnippet,
                                mountFolder(connect, '.tmp'),
                                mountFolder(connect, cegedimConfig.app)
                            ];
                        }
                    }
                }
     }

但我的问题是,在 Java 中,应用程序的上下文根是 mdp-web/

但在 AngularJS 中,我的 uri 类似于:/api/users

$resource('/api/users', {}, {
                query: {
                    isArray: true,
                    method:'GET',
                    cache: HttpCache
                }
            });

我想代理所有 /api/ uri,但重定向到 /mdp-web/api

是否可以使用 grunt-connect-proxy 来做到这一点(也许使用 rewrite 属性)?

如果你有想法,我真的接受它!

【问题讨论】:

    标签: node.js angularjs gruntjs


    【解决方案1】:

    使用重写规则:

    proxies: [
      {
         context:'/api',
         host: 'localhost',
         port: 8080,
         https: false,
         changeOrigin: true,
         rewrite: {
           '^/api': '/mdp-web/api'
         }
      }
    ]
    

    【讨论】:

      猜你喜欢
      • 2015-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-05
      相关资源
      最近更新 更多