当使用Gatsby在Vagrant上运行时(通过Virtualbox)我无法使端口转发工作。
Gatsby默认运行在localhost端口8000上。
我的Vagrantfile似乎使用以下内容转发正确的端口:
config.vm.network "forwarded_port", guest: 8000, host: 8000
当我使用yarn develop
在Vagrant框上启动Gatsby时,访客框上的所有内容都显示正常,应用程序在localhost上运行:8000
info bootstrap finished - 7.354 s
DONE Compiled successfully in 9091ms
You can now view foo-bar-org in the browser.
http://localhost:8000/
我可以在访客框上运行curl http://localhost:8000
以验证它确实在本地提供内容。
当我进入浏览器并尝试访问http://localhost:8000时,回到主机框上,它显示“Localhost拒绝连接”。
在访客框上运行netstat -tulnp | grep 8000
我得到以下内容:
tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN 1909/node
在主机框上运行相同的输出:
tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN 13827/VBoxHeadless
答案 0 :(得分:3)
我确实通过改变我在访客箱上运行盖茨比的方式来实现这一目标。似乎gatsby develop -H 0.0.0.0
将让Gatsby监听来自所有主机的连接。然后netstat -tulnp | grep 8000
输出更改为:
tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN 2348/node
我回答了我自己的问题,以防它帮助了其他人,但是如果有人可以想出更好的方法来做到这一点,Gatsby仍然只是在本地主人那里听,那么我更愿意回答并接受这个答案