# Using SSL in Proxy and Serve URL with Bud

**URL:** https://discourse.roots.io/t/using-ssl-in-proxy-and-serve-url-with-bud/24628
**Category:** bud
**Tags:** sage10
**Created:** 2023-01-24T06:11:40Z
**Posts:** 5

## Post 1 by @samfrank — 2023-01-24T06:11:40Z

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/](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?

---

## Post 2 by @strarsis — 2023-01-25T07:28:13Z

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`.

---

## Post 3 by @upperhouse — 2023-01-26T15:59:27Z

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.

---

## Post 4 by @strarsis — 2023-01-26T16:48:45Z

> [@upperhouse](#):
>
> `@certs`

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

---

## Post 5 by @chrillep — 2024-01-31T20:12:50Z

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:

- [Setting options | bud.js](https://bud.js.org/reference/bud.serve/setting-options#ssl)
- [https://nodejs.org/api/os.html#oshomedir](https://nodejs.org/api/os.html#oshomedir)
