首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >grunt contrib-connect代理给出错误500。如何调试?

grunt contrib-connect代理给出错误500。如何调试?
EN

Stack Overflow用户
提问于 2015-04-23 21:23:49
回答 1查看 1.8K关注 0票数 3

我想要将http://localhost:9000/imageshttp://localhost:9000/rest代理给https://remotehost/imageshttps://remotehost/rest,但这两个都出现了错误500。我做错了什么?如何调试这个?下面是我的配置:

代码语言:javascript
复制
        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 bug我没有得到关于为什么会出现这个错误的额外信息。谢谢!https://github.com/gruntjs/grunt-contrib-connect/issues/176

EN

回答 1

Stack Overflow用户

发布于 2017-12-31 00:26:56

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

我使用grunt connect-proxy2以以下方式运行了一个成功的配置:

代码语言:javascript
复制
{ /* 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为:

代码语言:javascript
复制
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了。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29824832

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档