如何从主机请求grunt服务?

时间:2014-06-27 04:13:31

标签: networking gruntjs virtual-machine

尝试使用yeoman在虚拟机上设置角度,以避免使用软件包管理来破坏我的计算机。

使用yo myproject生成项目后,全局安装角度&在本地,使用bower和更多依赖项安装grunt,我能够使用grunt serve

运行服务器

可以通过localhost从VM访问wget localhost,但不会从主机加载/etc/network/interface

我已尝试将文件{{1}}修改为static address并从浏览器访问静态IP,并通过端口转发访问set dynamic DHCP

host:3090; guest:9000

没有效果,浏览器无法建立连接:

  

Firefox无法在

建立与服务器的连接

我想上传更多有用的文件/输出以提供更多上下文,但作为一个新的grunt用户,我不知道在哪里看。

1 个答案:

答案 0 :(得分:8)

设置connect-middleaware侦听0.0.0.0 ip地址以确保主机可访问。

您可以像这样编辑Gruntfile.js。

connect中查找grunt.initConfig({});任务,将options中的主机名更改为0.0.0.0

它应该是这样的:

// The actual grunt server settings
connect: {
  options: {
    port: 9000,
    // Change this to '0.0.0.0' to access the server from outside.
    hostname: '0.0.0.0',
    livereload: 35729
  },
  livereload: {
    options: {
      open: true,
      base: [
        '.',
        'examples'
      ]
    }
  }
},

运行grunt serve,尝试使用vm ip从主机访问ip。它应该可用。