javascript - 如何让端口转发与 gatsby 和 vagrant 或 virtualbox 一起使用
问题描述
当使用在 Vagrant(通过 Virtualbox)上运行的Gatsby时,我无法让端口转发工作。
Gatsby 默认在 localhost 端口 8000 上运行。
我的 Vagrantfile 似乎使用以下内容转发了正确的端口:
config.vm.network "forwarded_port", guest: 8000, host: 8000
yarn develop
当我在Vagrant 框中使用
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
解决方案
我确实通过改变我在访客包厢上运行 Gatsby 的方式来完成这项工作。似乎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 仍然只在 localhost 上听,那么我更喜欢这个答案并接受这个答案。
推荐阅读
- ldap - 无法在 python 中从 LDAP 检索条目
- firebase - 如何从flutter中存在于firebase存储中的文件的url获取文件名?
- vba - 从功能区上的按钮将邮件移动到文件夹
- android - 更改 Android 启动器图标,如 Instagram/Todoist
- java - java.lang.IllegalStateException:当我有一个 BottomNavigationBar 时已经添加了片段 - 可能是片段的多个实例
- python - 请求请求时,我每隔一次,每隔一次,一些象形文字就会得到页面的可读正文
- typescript - 打字稿循环对象重写自身属性
- apache-spark - 安装具有 hive 3.1.2 的 Spark
- twitter-bootstrap - Bootstrap:多个目标:崩溃超出预期
- javascript - 如何根据表单突出显示 svg 地图图像