How to access specific port in vagrant box laravel

2019-08-15 06:39发布

问题:

I'm working on a node project on my vagrant laravel/homestead box. Everything works fine, I can access the project when I go to the host define in my /etc/hosts :

192.168.10.10 project

But, I'm trying to build and watch my project with webpack, so I installed webpack-dev-server and I can run it :

http://localhost:8080/
webpack result is served from /
content is served from /home/vagrant/Workspace/Kanban
404s will fallback to /index.html
[...]
webpack: bundle is now VALID.

My problem is, when I try to access project:8080 with my browser, I get a loading error.

A netstat -an | grep 8080 in the vagrant shows me that the box is listening. I tried to forward ports using homestead.yaml

ports:
  - send: 8080
    to: 8080
    protocol: tcp

But with or without port forwarding, all I get is an error page.

What can I do to make my webpack watcher work ?

回答1:

Okay, I finnaly found the answer. The problem was about not ports but the dev-server. It is configured by default to work only on the localhost. The solution was to add a rule to the configuration :

 devServer     : {
            [...]
            , host          : '0.0.0.0'
    }

Setting the host to '0.0.0.0' allows the dev-server to be accessible from anywhere, therefore, to my "real" host. I found the explanation on a GitHub issue. Too bad that the arguments list wasn't on the official documentation.