Skip to content

Allow custom domains in Vite's allowedHosts#51395

Merged
ryanclark merged 2 commits intomasterfrom
ryan/vite-6-allowed-hosts
Jan 23, 2025
Merged

Allow custom domains in Vite's allowedHosts#51395
ryanclark merged 2 commits intomasterfrom
ryan/vite-6-allowed-hosts

Conversation

@ryanclark
Copy link
Copy Markdown
Member

#51356 introduces the change of setting allowedHost to whatever the domain of the proxy target is, if it isn't localhost. That doesn't really work for my setup, and possibly others, as I use a different domain than localhost and the proxy target. This allows the option of setting a VITE_HOST environment variable (I followed the same convention in TAG), so we're not allowing all hosts.

@ryanclark ryanclark requested review from avatus and ravicious January 23, 2025 08:09
@ryanclark ryanclark added the no-changelog Indicates that a PR does not require a changelog entry label Jan 23, 2025
@github-actions github-actions bot requested review from kimlisa and rudream January 23, 2025 08:09
}

return [];
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be something like this to allow target and VITE_HOST at the same time because why not.

function resolveAllowedHost(target: string) {
  const allowedHosts = [];
  if (process.env.VITE_HOST) {
    allowedHosts.push(process.env.VITE_HOST);
  }

  if (target !== DEFAULT_PROXY_TARGET) {
    const { hostname } = new URL(`http://${target}`);

    allowedHosts.push(hostname);
  }

  return allowedHosts;
}

I guess it all comes down to which domains you have in the cert that Vite uses? But I noticed that the docs say "When using HTTPS, this check is skipped" and that is true, but the thing that falls apart without allowedHosts is websockets (and thus HMR).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think if your cert accepts localhost it'll still work without setting allowedHosts - but first Vite will try the hostname you're using, so there will be one error in the console always, but HMR would still work

I think your suggestion is good, I'll add it

@ryanclark ryanclark force-pushed the ryan/vite-6-allowed-hosts branch 2 times, most recently from 23307c5 to 6f857e3 Compare January 23, 2025 11:18
@ryanclark ryanclark force-pushed the ryan/vite-6-allowed-hosts branch from 6f857e3 to 0e8e356 Compare January 23, 2025 11:43
@ryanclark ryanclark enabled auto-merge January 23, 2025 11:43
@ryanclark ryanclark added this pull request to the merge queue Jan 23, 2025
Merged via the queue into master with commit 14132e4 Jan 23, 2025
@ryanclark ryanclark deleted the ryan/vite-6-allowed-hosts branch January 23, 2025 15:57
carloscastrojumo pushed a commit to carloscastrojumo/teleport that referenced this pull request Feb 19, 2025
* Allow custom domains in Vite's allowedHosts

* Allow both VITE_HOST and the target to be allowedHosts
ravicious pushed a commit that referenced this pull request Feb 6, 2026
* Allow custom domains in Vite's allowedHosts

* Allow both VITE_HOST and the target to be allowedHosts
github-merge-queue bot pushed a commit that referenced this pull request Feb 9, 2026
* Bump the electron group across 1 directory with 4 updates

* Bump the electron group across 1 directory with 4 updates

Bumps the electron group with 4 updates in the / directory: [node-pty](https://github.com/microsoft/node-pty), [electron](https://github.com/electron/electron), [electron-updater](https://github.com/electron-userland/electron-builder/tree/HEAD/packages/electron-updater) and [electron-vite](https://github.com/alex8088/electron-vite).

Updates `node-pty` from 1.1.0-beta35 to 1.1.0
- [Release notes](https://github.com/microsoft/node-pty/releases)
- [Commits](microsoft/node-pty@v1.1.0-beta35...v1.1.0)

Updates `electron` from 39.2.2 to 40.1.0
- [Release notes](https://github.com/electron/electron/releases)
- [Commits](electron/electron@v39.2.2...v40.1.0)

Updates `electron-updater` from 6.7.0 to 6.7.3
- [Release notes](https://github.com/electron-userland/electron-builder/releases)
- [Changelog](https://github.com/electron-userland/electron-builder/blob/master/packages/electron-updater/CHANGELOG.md)
- [Commits](https://github.com/electron-userland/electron-builder/commits/electron-updater@6.7.3/packages/electron-updater)

Updates `electron-vite` from 4.0.1 to 5.0.0
- [Release notes](https://github.com/alex8088/electron-vite/releases)
- [Changelog](https://github.com/alex8088/electron-vite/blob/master/CHANGELOG.md)
- [Commits](alex8088/electron-vite@v4.0.1...v5.0.0)

---
updated-dependencies:
- dependency-name: node-pty
  dependency-version: 1.1.0
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: electron
- dependency-name: electron
  dependency-version: 40.1.0
  dependency-type: direct:development
  update-type: version-update:semver-major
  dependency-group: electron
- dependency-name: electron-updater
  dependency-version: 6.7.3
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: electron
- dependency-name: electron-vite
  dependency-version: 5.0.0
  dependency-type: direct:development
  update-type: version-update:semver-major
  dependency-group: electron
...

Signed-off-by: dependabot[bot] <support@github.com>

* Revert unnecessary updates

* Bump Node.js to 24

* Add node-pty prebuilds to `x64ArchFiles`

* Update node-pty to 1.2.0-beta.10

* Add fix for Wayland

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Grzegorz Zdunek <grzegorz.zdunek@goteleport.com>
Co-authored-by: Rafał Cieślak <rafal.cieslak@goteleport.com>

* Update Vite & related packages to latest

* Upgrade vite to 6.0.11 (#51356)

* Allow custom domains in Vite's allowedHosts (#51395)

* Allow custom domains in Vite's allowedHosts

* Allow both VITE_HOST and the target to be allowedHosts

* Use exact dep versions as v18

I think it'd have been enough to update `@vitejs/plugin-react-swc` to
3.9.0, but just to be sure I changed the versions to match v18.

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Grzegorz Zdunek <grzegorz.zdunek@goteleport.com>
Co-authored-by: Ryan Clark <ryan.clark@goteleport.com>
Co-authored-by: Michael <michael.myers@goteleport.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog Indicates that a PR does not require a changelog entry size/sm ui

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants