Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

forwarding grunt connect to different url #236

Open
mahermahouachi opened this issue Dec 11, 2017 · 2 comments
Open

forwarding grunt connect to different url #236

mahermahouachi opened this issue Dec 11, 2017 · 2 comments

Comments

@mahermahouachi
Copy link

mahermahouachi commented Dec 11, 2017

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 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

@mahermahouachi
Copy link
Author

please guys i need help

@lrkwz
Copy link

lrkwz commented Jan 9, 2018

@mahermahouachi take a look at https://stackoverflow.com/a/48035737/509565 hope it helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants