0

我正在我的 Windows 开发盒上运行 grunt/node/famo.us 的演示应用程序。当我使用 Chrome 访问 localhost:1377 时,在那台机器上一切正常。现在我正在尝试使用 ipaddress:1377 从同一网络上的另一个盒子访问该站点,但 Chrome 说它找不到它。我已经完全禁用了 Windows 防火墙,但它仍然不会出现。是否支持远程调用 grunt 站点?我做错了什么吗?

这是我的 gruntfile.js:

/*global module:false*/

/*Generated initially from grunt-init, heavily inspired by yo webapp*/

module.exports = function(grunt) {
  'use strict';

  // Time how long tasks take. Can help when optimizing build times
  require('time-grunt')(grunt);

  // Load grunt config
  require('load-grunt-config')(grunt, {
    init: true,
    data: {
      config: {
        // Configurable paths
        app: 'app',
        dist: 'dist'
      }
    }
  });
};
4

2 回答 2

1

是的,支持远程呼叫。进入 Gruntfile.js 并将 grunt.initConfig 连接选项更改为以下内容。

grunt.initConfig({
    // .. Some config
    // ..
    connect: {
        options: {
            port: grunt.option('port') || 5555,
            livereload: 35729,
            // Change this to '0.0.0.0' to access the server from outside
            hostname: '0.0.0.0'
        },
        // Other Options..
        // ..
    },
    // .. More Config
    // ..
}

希望这可以帮助!

编辑:好的,那么试试这个..

/*global module:false*/

/*Generated initially from grunt-init, heavily inspired by yo webapp*/

module.exports = function(grunt) {
  'use strict';

  // Time how long tasks take. Can help when optimizing build times
  require('time-grunt')(grunt);

  // Load grunt config
  require('load-grunt-config')(grunt, {
    init: true,
    data: {
      config: {
        // Configurable paths
        app: 'app',
        dist: 'dist'
      },
      connect: {
          options: {
              port: grunt.option('port') || 5555,
              livereload: 35729,
              // Change this to '0.0.0.0' to access the server from outside
              hostname: '0.0.0.0'
          },
          livereload: {
              options: {
                  open: true,
                  base: [
                      '.tmp',
                      '<%= config.app %>'
                  ]
              }
          },
          dist: {
              options: {
                  open: true,
                  base: '<%= config.dist %>',
                  livereload: false
              }
          }
      }
    }
  });
};
于 2014-05-16T15:12:40.823 回答
0

在您的 grunt 文件连接选项中,尝试完全省略该hostname字段。过去,我遇到过 Express 和 Connect 的问题,其中定义主机名实际上导致服务器只能通过该主机名(例如 0.0.0.0、127.0.0.1 和 localhost)访问,而不是 NAT IP(例如 192.68. xx 或 10.0.xx)。我不明白为什么会这样,但值得一试。

于 2014-05-17T07:39:54.393 回答