Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] Auto detect Valet / Herd TLS certificates #180

Merged
merged 7 commits into from
Dec 15, 2023
Merged

[1.x] Auto detect Valet / Herd TLS certificates #180

merged 7 commits into from
Dec 15, 2023

Conversation

timacdonald
Copy link
Member

@timacdonald timacdonald commented Dec 9, 2022

This PR adds:

  • Valet / Herd certificate auto-detection (✨) and makes it the default for upcoming 1.x release.
  • Ability to opt-out of auto-detection detectTls: false.
  • CLI output to indicate when the Valet / Herd certificate is being used (when known).

Assume everywhere "Valet" is mentioned that it also applies to "Herd".

This PR allows teams with a mixture of Valet and non-Valet users to configure TLS certificates, without adding additional configuration.

The following standard Laravel plugin config supports both use-cases:

import fs from 'fs'
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';

export default defineConfig({
    plugins: [
        laravel({
            input: ['resources/css/app.css', 'resources/js/app.js'],
            refresh: true,
        }),
    ],
});

For Valet users, as long as a Valet certificate is found it will be used. Valet certificates are "guessed" in the same way they currently are.

  1. $CWD is used as the host.
  2. TLD is resolved from the Valet config.

For non-Valet users, you may specify the path to TLS certificates with the existing environment options.

VITE_DEV_SERVER_KEY=/path/to/key
VITE_DEV_SERVER_CERT=/path/to/cert

CLI output

We now output on the CLI when Vite certificates are in use. This will help users know when the Valet certificates have been auto-detected, etc.

Screen Shot 2022-12-09 at 12 30 28 pm

The valetTls option now has the following options.

laravel({
  // ...

  // Auto-detection.
  // - Host is guessed via convention.
  // - Missing certificates are ignored.
  // _

  // Explicitly use Valet certificates.
  // - Host is guessed via convention.
  // - Errors are thrown when missing certificates. 
  valetTls: true,

  // Explicitly use Valet certificates.
  // - Host specified is used.
  // - Errors are thrown when missing certificates. 
  valetTls: 'tim.dev',

  // Opt-out of auto-detection.
  valetTls: false,
}),

@innocenzi
Copy link
Contributor

innocenzi commented Dec 9, 2022

This would be amazing, except for the way the host is resolved. My opinion is still that .env is better suited for this task. Consider the following scenario:

  • A backend repository exists, it's an application that powers two brands
  • Teammate1 clones backend locally at ~/Code/<brand1-name>
  • Teammate2 clones backend locally at ~/Code/backend
  • Both teammates use Valet

In this situation, even if Teammate1 sets APP_ENV to backend.test, the Valet certificates will not be found because of its directory name. It will work fine for Teammate2.

To fix this issue, vite.config.ts would need to be altered, just because of one of the developer's environment.

Alternatively, resolving the host via the working directory can be done as a fallback if .env is still at http://localhost (or at a value for which no certificate can be found), if that was your concern.

(I still think valetTls shouldn't be a configuration option, or at least that without using it, the scenario above should also be handled.)

I really like your addition to the CLI output. Looks pretty nice and it's useful.

@jessarcher
Copy link
Member

Hey @innocenzi,

You're correct that we're concerned about APP_URL not being set correctly, but we're also concerned that it's not used by Valet to determine the link name or certificate location either. It just happens that it should match when configured correctly.

We prefer the working directory because that's what Valet uses by default. For cases where the Valet link name has been customised, the valetTls option can be used to pass the custom hostname. I can see how this might be an issue with your scenario, but I'm not sure how common it is, and it can be solved with some additional code in the team's vite.config.js.

Having said that, I'd love it if the auto-detection could handle custom link names.

I don't have a Mac and haven't used Valet, but from what I can tell, the valet link command uses symlinks to wire things up, making them effectively the source of truth. I'm wondering whether we can read the symlink name(s) pointing to the working directory to determine the hostname that Valet is using. I imagine we'd still need to fall back to the working directory name to handle valet park.

If that doesn't work out, I'm not completely opposed to using APP_URL as long as we also check the working directory.

@driesvints driesvints changed the title [0.8.x] Adds Valet certificate auto-detection. [0.8.x] Adds Valet certificate auto-detection Dec 12, 2022
@innocenzi
Copy link
Contributor

It just happens that it should match when configured correctly.

I understand the concern and that technically, the semantics don't match — however, in practice, this is the perfect fit for this option, I would argue.

If that doesn't work out, I'm not completely opposed to using APP_URL as long as we also check the working directory.

I think this would be the perfect compromise, if the solution above doesn't work.

@innocenzi
Copy link
Contributor

@timacdonald it's been a while, with the support or Herd now I thought this would be a good time to follow-up?

@timacdonald
Copy link
Member Author

@jessarcher and I have started talking about this again. We will circle back to it shortly and get things moving, whichever way.

@timacdonald
Copy link
Member Author

Will revisit this PR tomorrow and see if we can get it into shape for the 1.x release.

@timacdonald timacdonald self-assigned this Dec 13, 2023
@timacdonald timacdonald changed the title [0.8.x] Adds Valet certificate auto-detection [0.8.x] Auto detect Valet / Herd TLS certificates Dec 13, 2023
@timacdonald timacdonald changed the base branch from main to 1.x December 14, 2023 06:03
@timacdonald timacdonald changed the title [0.8.x] Auto detect Valet / Herd TLS certificates [1.x] Auto detect Valet / Herd TLS certificates Dec 14, 2023
@timacdonald timacdonald marked this pull request as ready for review December 15, 2023 06:01
@taylorotwell taylorotwell merged commit b2daa54 into laravel:1.x Dec 15, 2023
3 checks passed
tisnamuliarta referenced this pull request in tisnamuliarta/laravel-shadcn Mar 11, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [laravel-vite-plugin](https://github.com/laravel/vite-plugin) |
[`^0.8.0` ->
`^1.0.0`](https://renovatebot.com/diffs/npm/laravel-vite-plugin/0.7.8/1.0.2)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/laravel-vite-plugin/1.0.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/laravel-vite-plugin/1.0.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/laravel-vite-plugin/0.7.8/1.0.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/laravel-vite-plugin/0.7.8/1.0.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>laravel/vite-plugin (laravel-vite-plugin)</summary>

###
[`v1.0.2`](https://github.com/laravel/vite-plugin/blob/HEAD/CHANGELOG.md#v102---2024-02-28)

[Compare
Source](https://github.com/laravel/vite-plugin/compare/v1.0.1...v1.0.2)

- \[1.x] Fix HMR issue when `resources/lang` directory doesn't exist and
a symlink is present in the root directory by
[@&#8203;jessarcher](https://github.com/jessarcher) in
[https://github.com/laravel/vite-plugin/pull/285](https://github.com/laravel/vite-plugin/pull/285)

###
[`v1.0.1`](https://github.com/laravel/vite-plugin/blob/HEAD/CHANGELOG.md#v101---2023-12-27)

[Compare
Source](https://github.com/laravel/vite-plugin/compare/v1.0.0...v1.0.1)

- \[1.x] Simpler conditional by
[@&#8203;Jubeki](https://github.com/Jubeki) in
[https://github.com/laravel/vite-plugin/pull/273](https://github.com/laravel/vite-plugin/pull/273)
- \[1.x] Account for imported CSS files while cleaning by
[@&#8203;timacdonald](https://github.com/timacdonald) in
[https://github.com/laravel/vite-plugin/pull/275](https://github.com/laravel/vite-plugin/pull/275)
- \[1.x] Fix exit error messages by
[@&#8203;timacdonald](https://github.com/timacdonald) in
[https://github.com/laravel/vite-plugin/pull/276](https://github.com/laravel/vite-plugin/pull/276)

###
[`v1.0.0`](https://github.com/laravel/vite-plugin/blob/HEAD/CHANGELOG.md#v100---2023-12-19)

[Compare
Source](https://github.com/laravel/vite-plugin/compare/v0.8.1...v1.0.0)

- \[1.0] Drop CJS build and export types first by
[@&#8203;benmccann](https://github.com/benmccann) in
[https://github.com/laravel/vite-plugin/pull/235](https://github.com/laravel/vite-plugin/pull/235)
- \[1.x] Introduce `clean-orphaned-assets` binary by
[@&#8203;timacdonald](https://github.com/timacdonald) in
[https://github.com/laravel/vite-plugin/pull/251](https://github.com/laravel/vite-plugin/pull/251)
- \[0.8.x] Respect vite server.origin in viteDevServerUrl by
[@&#8203;nurdism](https://github.com/nurdism) in
[https://github.com/laravel/vite-plugin/pull/255](https://github.com/laravel/vite-plugin/pull/255)
- \[1.x] Vite 5 by
[@&#8203;timacdonald](https://github.com/timacdonald) in
[https://github.com/laravel/vite-plugin/pull/269](https://github.com/laravel/vite-plugin/pull/269)
- \[0.8.x] Fallback pages by
[@&#8203;timacdonald](https://github.com/timacdonald) in
[https://github.com/laravel/vite-plugin/pull/271](https://github.com/laravel/vite-plugin/pull/271)
- \[1.x] Auto detect Valet / Herd TLS certificates by
[@&#8203;timacdonald](https://github.com/timacdonald) in
[https://github.com/laravel/vite-plugin/pull/180](https://github.com/laravel/vite-plugin/pull/180)

###
[`v0.8.1`](https://github.com/laravel/vite-plugin/blob/HEAD/CHANGELOG.md#v081---2023-09-26)

[Compare
Source](https://github.com/laravel/vite-plugin/compare/v0.8.0...v0.8.1)

- \[0.8] Fix issue with `0.0.0.0` network resolution by
[@&#8203;timacdonald](https://github.com/timacdonald) in
[https://github.com/laravel/vite-plugin/pull/241](https://github.com/laravel/vite-plugin/pull/241)
- Upgrade vitest by
[@&#8203;sapphi-red](https://github.com/sapphi-red) in
[https://github.com/laravel/vite-plugin/pull/246](https://github.com/laravel/vite-plugin/pull/246)

###
[`v0.8.0`](https://github.com/laravel/vite-plugin/blob/HEAD/CHANGELOG.md#v080---2023-08-08)

[Compare
Source](https://github.com/laravel/vite-plugin/compare/v0.7.8...v0.8.0)

- fix: compile error following upgrade.md's vite to mix guide by
[@&#8203;AshboDev](https://github.com/AshboDev) in
[https://github.com/laravel/vite-plugin/pull/231](https://github.com/laravel/vite-plugin/pull/231)
- Support Laravel Herd by
[@&#8203;claudiodekker](https://github.com/claudiodekker) in
[https://github.com/laravel/vite-plugin/pull/233](https://github.com/laravel/vite-plugin/pull/233)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/tisnamuliarta/laravel-shadcn).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yMzAuMCIsInVwZGF0ZWRJblZlciI6IjM3LjIzMC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->
tisnamuliarta referenced this pull request in tisnamuliarta/laravel-shadcn Mar 22, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [laravel-vite-plugin](https://github.com/laravel/vite-plugin) |
[`^0.7.5` ->
`^1.0.0`](https://renovatebot.com/diffs/npm/laravel-vite-plugin/0.7.8/1.0.2)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/laravel-vite-plugin/1.0.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/laravel-vite-plugin/1.0.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/laravel-vite-plugin/0.7.8/1.0.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/laravel-vite-plugin/0.7.8/1.0.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>laravel/vite-plugin (laravel-vite-plugin)</summary>

###
[`v1.0.2`](https://github.com/laravel/vite-plugin/blob/HEAD/CHANGELOG.md#v102---2024-02-28)

[Compare
Source](https://github.com/laravel/vite-plugin/compare/v1.0.1...v1.0.2)

- \[1.x] Fix HMR issue when `resources/lang` directory doesn't exist and
a symlink is present in the root directory by
[@&#8203;jessarcher](https://github.com/jessarcher) in
[https://github.com/laravel/vite-plugin/pull/285](https://github.com/laravel/vite-plugin/pull/285)

###
[`v1.0.1`](https://github.com/laravel/vite-plugin/blob/HEAD/CHANGELOG.md#v101---2023-12-27)

[Compare
Source](https://github.com/laravel/vite-plugin/compare/v1.0.0...v1.0.1)

- \[1.x] Simpler conditional by
[@&#8203;Jubeki](https://github.com/Jubeki) in
[https://github.com/laravel/vite-plugin/pull/273](https://github.com/laravel/vite-plugin/pull/273)
- \[1.x] Account for imported CSS files while cleaning by
[@&#8203;timacdonald](https://github.com/timacdonald) in
[https://github.com/laravel/vite-plugin/pull/275](https://github.com/laravel/vite-plugin/pull/275)
- \[1.x] Fix exit error messages by
[@&#8203;timacdonald](https://github.com/timacdonald) in
[https://github.com/laravel/vite-plugin/pull/276](https://github.com/laravel/vite-plugin/pull/276)

###
[`v1.0.0`](https://github.com/laravel/vite-plugin/blob/HEAD/CHANGELOG.md#v100---2023-12-19)

[Compare
Source](https://github.com/laravel/vite-plugin/compare/v0.8.1...v1.0.0)

- \[1.0] Drop CJS build and export types first by
[@&#8203;benmccann](https://github.com/benmccann) in
[https://github.com/laravel/vite-plugin/pull/235](https://github.com/laravel/vite-plugin/pull/235)
- \[1.x] Introduce `clean-orphaned-assets` binary by
[@&#8203;timacdonald](https://github.com/timacdonald) in
[https://github.com/laravel/vite-plugin/pull/251](https://github.com/laravel/vite-plugin/pull/251)
- \[0.8.x] Respect vite server.origin in viteDevServerUrl by
[@&#8203;nurdism](https://github.com/nurdism) in
[https://github.com/laravel/vite-plugin/pull/255](https://github.com/laravel/vite-plugin/pull/255)
- \[1.x] Vite 5 by
[@&#8203;timacdonald](https://github.com/timacdonald) in
[https://github.com/laravel/vite-plugin/pull/269](https://github.com/laravel/vite-plugin/pull/269)
- \[0.8.x] Fallback pages by
[@&#8203;timacdonald](https://github.com/timacdonald) in
[https://github.com/laravel/vite-plugin/pull/271](https://github.com/laravel/vite-plugin/pull/271)
- \[1.x] Auto detect Valet / Herd TLS certificates by
[@&#8203;timacdonald](https://github.com/timacdonald) in
[https://github.com/laravel/vite-plugin/pull/180](https://github.com/laravel/vite-plugin/pull/180)

###
[`v0.8.1`](https://github.com/laravel/vite-plugin/blob/HEAD/CHANGELOG.md#v081---2023-09-26)

[Compare
Source](https://github.com/laravel/vite-plugin/compare/v0.8.0...v0.8.1)

- \[0.8] Fix issue with `0.0.0.0` network resolution by
[@&#8203;timacdonald](https://github.com/timacdonald) in
[https://github.com/laravel/vite-plugin/pull/241](https://github.com/laravel/vite-plugin/pull/241)
- Upgrade vitest by
[@&#8203;sapphi-red](https://github.com/sapphi-red) in
[https://github.com/laravel/vite-plugin/pull/246](https://github.com/laravel/vite-plugin/pull/246)

###
[`v0.8.0`](https://github.com/laravel/vite-plugin/blob/HEAD/CHANGELOG.md#v080---2023-08-08)

[Compare
Source](https://github.com/laravel/vite-plugin/compare/v0.7.8...v0.8.0)

- fix: compile error following upgrade.md's vite to mix guide by
[@&#8203;AshboDev](https://github.com/AshboDev) in
[https://github.com/laravel/vite-plugin/pull/231](https://github.com/laravel/vite-plugin/pull/231)
- Support Laravel Herd by
[@&#8203;claudiodekker](https://github.com/claudiodekker) in
[https://github.com/laravel/vite-plugin/pull/233](https://github.com/laravel/vite-plugin/pull/233)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/tisnamuliarta/laravel-shadcn).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yMzguMSIsInVwZGF0ZWRJblZlciI6IjM3LjIzOC4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants