Using SSL in Proxy and Serve URL with Bud

As a summary I am having issues using a proxy domain which is has a local SSL certificate and getting the yarn dev command to work as expected.

For context I am using the LocalWP to connect with my WPEngine sites, and use that as my virtual environments. I am using Sage 6.6.6 and corresponding packages.

For a while now, because I have moved over to using LocalWP application my Yarn Dev command doesn’t work, and I have been using the Yarn Build command, but time has come to try and work out what is going on. When using LocalWP it almost forces you to create a SSL certificate for your domain name (e.g https://domain.local/).

I have followed a couple of approaches that I have found on this forum, some that are using BrowserSync instead, I have tried this, however to no avail. So I am still attempting this using Bud JS and the app.serve method. Here is my config below:

    .proxy('https://domain.local/')

    .serve({
        url: new URL(`https://localhost:4000/`),
	cert: `/Users/USER/domain.local+1.pem`,
	key: `/Users/USER/domain.local+1-key.pem`,
    })

I have created localhost SSL using mkcert which allows domain.local to be secure and I can see this being reflect in chrome URL bar with the little padlock next to it.

However, when viewing the page I am getting this error ‘Error occurred while trying to proxy: localhost:4000/’

Has anyone run into this issue before?

Can bud (that runs as nodejs process) reach/resolve localhost:4000?
You can try something like wget/curl from within the same terminal bud would run and see whether it can actually connect to localhost:4000.

I just wrangled with this some yesterday, with a new build of Sage and Bud 6.6.9.
Here is the recipe I final got to work:

    .setPath({
			'@certs': 'src/certs',
      '@images': 'resources/images'
		})

    .proxy('https://ratiotwo.test')
    .serve({
      host: 'ratiotwo.test:3000',
      cert: app.path('@certs/ratiotwo.test.crt'),
      key: app.path('@certs/ratiotwo.test.key'),
    })

Also, for whatever reason I had to clear my browser cache to get the hot reloading to start working.
Using valet to serve the site locally.

2 Likes

Interesting approach, I didn’t know this can simplified like this.

if using valet
you can use os to get the homedir and load the cert valet created.

bud.config.ts

import type { Bud } from "@roots/bud";
import * as os from "os";

/**
 * Bud config
 */
export default async (bud: Bud) => {
  bud
    .proxy(`https://projectname.test`)
    .serve({
      host: 'projectname.test',
      port: 4000,
      ssl: true,
      cert: bud.path(os.homedir() + '/.config/valet/Certificates/projectname.test.crt'),
      key: bud.path(os.homedir() + '/.config/valet/Certificates/projectname.test.key'),
    })

refs: