我在前端有一个使用 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 属性)来做到这一点?
如果你有一个想法,我真的接受它!