简体   繁体   English

浏览器同步代理未加载 Laravel

[英]Browser-sync proxy not loading with Laravel

I'm using browser-sync (v 2.27.9) and browser-sync-webpack-plugin (v 2.3.0) in my Laravel 8 project.我在我的 Laravel 8 项目中使用 browser-sync (v 2.27.9) 和 browser-sync-webpack-plugin (v 2.3.0)。 I've never had any problems with my setup until I cloned my project on a brand new Mac Studio with MacOS Monterey (v12.3).在我使用 MacOS Monterey (v12.3) 在全新的 Mac Studio 上克隆我的项目之前,我的设置从未遇到任何问题。 Until now, Browser-sync has always proxied localhost:8000 and loaded up just fine on localhost:3000.到目前为止,Browser-sync 一直代理 localhost:8000 并在 localhost:3000 上正常加载。

localhost:8000 is loading normally, it's just the browser-sync proxy that does not load. localhost:8000 加载正常,只是浏览器同步代理没有加载。 The browser-sync UI loads just fine on port 3001 as well.浏览器同步 UI 在端口 3001 上也可以正常加载。 I have tried re-installing both npm packages, restarting my computer, killing all ports, starting and re-starting the php development server, running npm run watch over and over, checking in multiple browsers, and trying 127.0.0.1 instead of "localhost". I have tried re-installing both npm packages, restarting my computer, killing all ports, starting and re-starting the php development server, running npm run watch over and over, checking in multiple browsers, and trying 127.0.0.1 instead of "localhost ”。

Here's my webpack.mix.js settings, which again have always worked in the past:这是我的 webpack.mix.js 设置,这些设置在过去一直有效:

    .browserSync({
        proxy: 'http://localhost:8000/',
        files: [
            'app/**/*',
            'public/**/*',
            'resources/views/**/*',
            'resources/js/**/*' ,
            'resources/js/**/*/*',
            'resources/lang/**/*',
            'routes/**/*',
        ],
    })

And I am seeing a permanent spinning icon in the browser at localhost:3000.我在 localhost:3000 的浏览器中看到了一个永久的旋转图标。 In the developer tools Network tab, it says localhost has a status of (pending).在开发人员工具的网络选项卡中,它说 localhost 的状态为(待定)。

In the browser-sync help page, it says "99% of the time, it's because your web page doesn't have a body tag".在浏览器同步帮助页面中,它说“99% 的时间,这是因为您的 web 页面没有正文标签”。 I have confirmed my website has a body tag, so this problem must fall in the 1% category.我已经确认我的网站有一个 body 标签,所以这个问题必须属于 1% 的类别。

Figured it out.弄清楚了。 I needed to change "localhost" to 127.0.0.1 in the proxy URL.我需要在代理 URL 中将“localhost”更改为 127.0.0.1。 Still unclear why localhost has worked in the past but does not work now.仍然不清楚为什么 localhost 过去有效但现在无效。

    .browserSync({
        proxy: 'http://127.0.0.1:8000/',

In my case commenting this entry in /etc/hosts helped在我的情况下,在/etc/hosts中评论这个条目有帮助

 #::1    localhost

source: Chrome can't open localhost:3000 with Gulp / BrowserSync来源: Chrome 无法使用 Gulp / BrowserSync 打开 localhost:3000

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM