grunt-connect-proxy forwarding grunt connect to different url
Asked Answered
S

0

8

Issue:

I'm trying to connect my grunt server 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 command 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

Slovak answered 6/12, 2017 at 17:40 Comment(2)
Is your application on 9000 port running via https?Kacey
@Kacey no it's running on port 9000 via httpSlovak

© 2022 - 2024 — McMap. All rights reserved.