Grunt-connect-proxy重定向?

时间:2013-11-07 09:15:06

标签: node.js angularjs gruntjs

我在前端有一个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 / uris,但重定向到/ mdp-web / api

是否可以使用grunt-connect-proxy(可能带有重写属性)来做到这一点?

如果你有个主意,我真的会接受它!

1 个答案:

答案 0 :(得分:2)

使用重写规则:

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