如何从另一个框访问grunt网站

时间:2014-05-16 14:45:22

标签: windows node.js gruntjs famo.us

我在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'
      }
    }
  });
};

2 个答案:

答案 0 :(得分: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
              }
          }
      }
    }
  });
};

答案 1 :(得分:0)

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