grunt-connect-proxy转发grunt连接到不同的url

时间:2017-12-06 17:40:47

标签: javascript node.js gruntjs grunt-connect-proxy

问题:

我试图将我的grunt服务器连接到在端口8080上运行的api服务。

问题:

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

我认为即使使用'configureProxies:server',应用程序也不会将请求重定向到好的服务器。

运行命令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...

我的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'
 ]);

我的期望: 当我对以下路径"/_ah,/secured,/oauth2login,/oauth2callback"发出请求时,它应该将请求重定向到'localhost:8080'但问题仍然是'localhost:9000

0 个答案:

没有答案