【问题标题】:How to access grunt site from another box如何从另一个盒子访问 grunt 站点
【发布时间】:2014-05-16 14:45:22
【问题描述】:

我正在运行 grunt/node/famo.us 以在我的 Windows 开发盒上运行演示应用程序。当我使用 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'
      }
    }
  });
};

【问题讨论】:

    标签: windows node.js gruntjs famo.us


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

    【讨论】:

    • 我已将我的 grunt 配置文件添加到问题中,因为我看不到我会将您显示的内容放在哪里。谢谢!
    • 好的.. 我将“连接”配置的全部内容添加到您的 gruntfile.js
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-05
      • 2014-02-13
      • 1970-01-01
      • 1970-01-01
      • 2014-12-16
      • 1970-01-01
      • 1970-01-01
      • 2015-12-25
      相关资源
      最近更新 更多