【问题标题】:grunt-contrib-connect proxy gives error 500. How to debug?grunt-contrib-connect 代理给出错误 500。如何调试?
【发布时间】:2015-07-01 17:17:31
【问题描述】:

我想将 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 serve --debug 错误我没有得到关于为什么会出现这个错误的额外信息。 谢谢! https://github.com/gruntjs/grunt-contrib-connect/issues/176

【问题讨论】:

  • 你解决了这个问题吗?
  • 我想我更新了 NodeJS 或 Grunt....

标签: node.js https gruntjs


【解决方案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

【讨论】:

  • 这似乎不适用于自签名证书。
猜你喜欢
  • 2015-08-24
  • 2015-01-25
  • 1970-01-01
  • 1970-01-01
  • 2015-11-13
  • 2017-06-12
  • 1970-01-01
  • 1970-01-01
  • 2014-03-05
相关资源
最近更新 更多