Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grunt-connect-proxy redirect?

I've got an application with AngularJS in front-end and Java Spring 3 in backend.

So when i run grunt-server i use grunt-connect-proxy to contact the backend part form the frontend part.

So my connect configuration is like that :

     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)
                            ];
                        }
                    }
                }
     }

But my matter is that in Java the context-root of the application is mdp-web/

But in AngularJS my uri's are like : /api/users

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

I want to proxy all the /api/ uris but with a redirection to /mdp-web/api

Is it possible to do that with grunt-connect-proxy (maybe with rewrite property) ?

If you get an idea i take it really !

like image 831
Thomas Pons Avatar asked Nov 01 '22 11:11

Thomas Pons


1 Answers

Use a rewrite rule:

proxies: [
  {
     context:'/api',
     host: 'localhost',
     port: 8080,
     https: false,
     changeOrigin: true,
     rewrite: {
       '^/api': '/mdp-web/api'
     }
  }
]
like image 194
Mickaël Gauvin Avatar answered Nov 10 '22 03:11

Mickaël Gauvin