grunt-contrib-connect代理提供错误500.如何调试?

时间:2015-04-23 13:23:49

标签: node.js https gruntjs

我想将http://localhost:9000/imageshttp://localhost:9000/rest代理到https://remotehost/imageshttps://remotehost/rest,但我收到错误500。我究竟做错了什么?如何调试? 这是我的配置:

        connect: {
        options: {
            port: 9000,
            // Change this to '0.0.0.0' to access the server from outside.
            hostname: 'localhost',
            livereload: 35729
        },
        proxies: [
            {
                context: '/images',
                host: remotehost,
                port: 443,
                https: true,
                changeOrigin: true,
                xforward: false,
                rejectUnauthorized: false
            }
        ],
        livereload: {
            options: {
                open: true,
                base: [
                    '.tmp',
                    '<%= yeoman.app %>'
                ],
                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(connect.static(base));
                    });

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

                    return middlewares;
                }
            }
        },

我试图调试这个正在运行的grunt服务--debug错误我没有得到关于我为什么会收到此错误的额外信息。 谢谢! https://github.com/gruntjs/grunt-contrib-connect/issues/176

1 个答案:

答案 0 :(得分:1)

grunt-connect-proxy似乎已被放弃:请参阅https://github.com/drewzboto/grunt-connect-proxy/issues/144

我使用grunt-connect-proxy2以下列方式运行成功配置:

{ /* package.json */
  "name": "grunt-connect-sample",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {},
  "devDependencies": {
    "grunt": "^1.0.1",
    "grunt-connect-proxy2": "^2.0.0",
    "grunt-contrib-connect": "^1.0.2",
    "grunt-contrib-jshint": "^1.1.0",
    "grunt-contrib-watch": "^1.0.0"
  }
}

然后Gruntfile.js是:

module.exports = function (grunt) {

    grunt.initConfig({
        jshint: {
            files: ['Gruntfile.js', 'src/**/*.js', 'test/**/*.js'],
            options: {
                globals: {
                    jQuery: true
                }
            }
        },
        watch: {
            files: ['<%= jshint.files %>'],
            tasks: ['jshint']
        },

        connect: {
            server: {
                options: {
                    port: 9000,
                    base: 'src/webroot',
                    keepalive: true,
                    middleware: function (connect, options, defaultMiddleware) {
                        var proxy = require('grunt-connect-proxy2/lib/utils').proxyRequest;
                        return [
                            // Include the proxy first
                            proxy
                        ].concat(defaultMiddleware);
                    }
                },
                proxies: [
                    {
                        context: '/google',
                        host: 'www.google.it',
                        port: 443,
                        https: true,
                        rewrite: {
                            '^/google': ''
                        }
                    }
                ]
            }
        }
    });

    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-connect');
    grunt.loadNpmTasks('grunt-connect-proxy2');

    grunt.registerTask('default', ['jshint', 'configureProxies:server', 'connect:server']);

};

然后你可以访问http://localhost:9000/google