mrcsmcln's avatar

Laravel Valet not playing nice with BrowserSync

The title pretty much says it all. I've configured my valet park'd my ~/Sites directory and tried using mix.browserSync({proxy: 'site.dev'}), but Google tells me the site unexpectedly disconnected. I've tried changing the BrowserSync port, and instead, Chrome completely crashes.

Thoughts?

0 likes
17 replies
jcsarda's avatar

I'm having the same issue. Let me know if you come up with a solution. I'm gonna try to figure it out later on today.

mrcsmcln's avatar

It looks like my issue was only occurring when the site was secured via HTTPS. That might help.

jcsarda's avatar

Mine was conflicting with another server I had running on :3000... Thanks!

nanosolutions's avatar

Still not working for me, it only work on :3000 not on valet domain ?

chasegiunta's avatar

I was having issues getting BrowserSync to play nice with Valet (Caddy server) using HTTPS. Chrome couldn't verify the certificate to the proxy (localhost:3000) so it would give me the terrible "do you want to proceed" error and show the red X over the padlock in my URL bar.

So I followed the directions here: https://certsimple.com/blog/localhost-ssl-fix and since I was using gulp to initiate browsersync, added my new key and cert paths in my gulp.js file

browserSync.init({
  proxy:  "https://domain.dev",
  https: {
    key: "/Users/chase/.localhost-ssl/key.pem",
    cert: "/Users/chase/.localhost-ssl/cert.pem"
  }
});

Now it works like a charm!

6 likes
vanderbake's avatar

If you're using valet secure and want browserSync play nicely with your test domain, here is a snippet which will make it secure without any errors:

// At the top of you webpack.mix.js file
const domain = 'yourdomain.test';
const homedir = require('os').homedir();

// The mix script:
mix.browserSync({
      proxy: 'https://' + domain,
      host: domain,
      open: 'external',
      https: {
        key: homedir + '/.valet/Certificates/' + domain + '.key',
        cert: homedir + '/.valet/Certificates/' + domain + '.crt',
      },
  })

On npm run watch this will load "https://yourdomain.test:3000" with valid certificates.

Maybe this helps someone stumbling across this. :-)

10 likes
Manus's avatar

This helped me tremendously. Thanks!

schnetzi's avatar

@vanderbake thanks for your solution. I just had to change the paths of the certificate to

key: homedir + "/.config/valet/Certificates/" + domain + ".key",
cert: homedir + "/.config/valet/Certificates/" + domain + ".crt"

and it worked perfectly!

I was trying to use the environment variables to have it more generic, but that didn't work for me.

9 likes
robertosantana's avatar

If you use MAMP this can be solved with the certificates generated by MAMP like this

const domain = 'yourdomain.test';
const certsPath = '/Applications/MAMP/Library/OpenSSL/certs/';

mix.browserSync({
    proxy: 'https://' + domain,
    host: domain,
    open: false,
    https: {
        key: certsPath + domain + '.key',
        cert: certsPath + domain + '.crt',
    },
});

Please or to participate in this conversation.