Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to request grunt serve from host machine?

Trying to setup angular on a virtual machine with yeoman to avoid breaking my machine with the packages management.

After generate the project with yo myproject, install angular globally & locally, install grunt with bower and more dependencies, I'm able to run the server using grunt serve

The localhost is accessible from the VM via wget localhost, but it does not load from the host.

I've tried modifying the file /etc/network/interface to static address and accessing the static IP from a browser, and also to set dynamic DHCP with port forwarding

host:3090; guest:9000

None have worked, the browser can't make a connection:

Firefox can't establish a connection to the server at

I would like to upload more useful files/output to give more context, but as a new grunt user I have no idea where to look.

like image 454
Lucio Avatar asked Feb 12 '23 15:02

Lucio


1 Answers

set connect-middleaware listen on 0.0.0.0 ip address to ensure host accessible.

You can edit your Gruntfile.js like this.

Find connect task in grunt.initConfig({}); change the hostname in the options to 0.0.0.0

It should look like this:

// 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'
      ]
    }
  }
},

run grunt serve, try to use vm ip to access ip from host. it should available.

like image 195
Bob Yuan Avatar answered Feb 22 '23 20:02

Bob Yuan