grunt-connect-proxy in Gruntfile.js requests not automaticaly redirected

8 views
Skip to first unread message

Maher Mahouachi

unread,
Dec 13, 2017, 7:02:22 AM12/13/17
to Angular and AngularJS discussion

Issue:


i'm trying to connect my grunt server "angular application" to my api service running on port 8080.


Problem:


:9000/secured/api/users/portal/me Failed to load resource: the server responded with a status of 503 (Service Unavailable)

I think even with 'configureProxies:server' the application is not redirecting the request to the good server.

My Console: after running commande grunt

Running "sass:dist" (sass) task

Running "copy:dev" (copy) task
Copied 80 files

Running "clean:server" (clean) task
>> 0 paths cleaned.

Running "wiredep:app" (wiredep) task

Running "configureProxies:server" (configureProxies) task
Proxy created for: /_ah,/secured,/oauth2login,/oauth2callback to localhost:8080

Running "connect:livereload" (connect) task
Started connect web server on http://localhost:9000

Running "watch" task
Waiting...


My Gruntfile.js:

require('load-grunt-tasks')(grunt);

var pkg = grunt.file.readJSON('package.json');
grunt
.loadNpmTasks('grunt-connect-proxy');
var serveStatic = require('serve-static');
var serveIndex = require('serve-index');

var options = {
...
connect
: {
  options
: {
    livereload
: true,
    hostname
: 'localhost',
   
base: 'app',
    port
: 9000
 
},
  proxies
: [
   
{
      context
: [
       
'/_ah',
       
'/secured',
       
'/oauth2login',
       
'/oauth2callback'
     
],
      host
: 'localhost',
      port
: 8080,
      https
: false,
      changeOrigin
: false,
      xforward
: false
   
}
 
],
  livereload
: {
    options
: {
      open
: true,
      middleware
: function (connect, options) {
       
if (!Array.isArray(options.base)) {
            options
.base = [options.base];
       
}

       
// Setup the proxy
       
var middlewares = [require('grunt-connect-proxy/lib/utils').proxyRequest];

       
// Serve static files.
        options
.base.forEach(function(base) {
            middlewares
.push(serveStatic(base));
       
});

       
// Make directory browse-able.
       
var directory = options.directory || options.base[options.base.length - 1];
        middlewares
.push(serveIndex(directory));

       
return middlewares;
     
}

   
}
 
}
 
...
 
}

 
var configs = require('load-grunt-configs')(grunt, options);

 
// Define the configuration for all the tasks
  grunt
.initConfig(configs);

  grunt
.registerTask('bumper', ['bump-only']);
  grunt
.registerTask('css', ['sass']);
  grunt
.registerTask('default', [
   
'sass',
   
'copy:dev',
   
'clean:server',
   
'wiredep',
   
'configureProxies:server',
   
'connect:livereload',
   
'watch'
 
]);


My expectations: 

When i do a request to the following paths "/_ah,/secured,/oauth2login,/oauth2callback" it should redirect the request to 'localhost:8080' but the problem that it still requesting 'localhost:9000


Maher Mahouachi

unread,
Dec 13, 2017, 7:02:22 AM12/13/17
to Angular and AngularJS discussion

Issue:


i'm trying to connect my grunt server to my api service running on port 8080.

Sander Elias

unread,
Dec 13, 2017, 10:59:21 AM12/13/17
to Angular and AngularJS discussion
Hi Maher,

I'm sorry, but I can't help you debugging your grunt files. I stopped using grunt short after gulp was introduced. The anguar CLI now takes care of this stuff for me.

Regards
Sander
Reply all
Reply to author
Forward
0 new messages