Skip to content

Commit

Permalink
rename env var
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Aug 1, 2024
1 parent 006348a commit 3110b2e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .changes/dev-url-localhost-mobile.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

`ios dev` and `android dev` now uses localhost for the development server unless running on an iOS device,
which still requires connecting to the public network address. To conditionally check this on your frontend
framework's configuration you can check for the existence of the `TAURI_DEV_PUBLIC_NETWORK_HOST_REQUIRED`
framework's configuration you can check for the existence of the `TAURI_DEV_HOST`
environment variable instead of checking if the target is iOS or Android (previous recommendation).
6 changes: 3 additions & 3 deletions examples/api/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Unocss from 'unocss/vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'
import { internalIpV4Sync } from 'internal-ip'

const publicNetwork = process.env.TAURI_DEV_PUBLIC_NETWORK_HOST_REQUIRED
const host = process.env.TAURI_DEV_HOST

// https://vitejs.dev/config/
export default defineConfig({
Expand All @@ -27,10 +27,10 @@ export default defineConfig({
clearScreen: false,
// tauri expects a fixed port, fail if that port is not available
server: {
host: publicNetwork ? '0.0.0.0' : false,
host: host ? '0.0.0.0' : false,
port: 1420,
strictPort: true,
hmr: publicNetwork
hmr: host
? {
protocol: 'ws',
host: internalIpV4Sync(),
Expand Down
8 changes: 4 additions & 4 deletions tooling/cli/src/mobile/ios/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ It also runs your `build.beforeDevCommand` which usually starts your frontend de
When connected to a physical iOS device, the public network address must be used instead of `localhost`
for the devUrl property. Tauri makes that change automatically, but your dev server might need
a different configuration to listen on the public address. You can check the `TAURI_DEV_PUBLIC_NETWORK_HOST_REQUIRED`
a different configuration to listen on the public address. You can check the `TAURI_DEV_HOST`
environment variable to determine whether the public network should be used or not."
)]
pub struct Options {
Expand Down Expand Up @@ -83,7 +83,7 @@ pub struct Options {
/// it is your responsability to set up your development server to listen on this address
/// by using 0.0.0.0 as host for instance.
///
/// When this is set or when running on an iOS device the CLI sets the `TAURI_DEV_PUBLIC_NETWORK_HOST_REQUIRED`
/// When this is set or when running on an iOS device the CLI sets the `TAURI_DEV_HOST`
/// environment variable so you can check this on your framework's configuration to expose the development server
/// on the public network address.
#[clap(long)]
Expand Down Expand Up @@ -265,7 +265,7 @@ fn use_network_address_for_dev_url(
println!(
"Replacing devUrl host with {ip}. {}. {}.",
"If your frontend is not listening on that address, try configuring your development server to use 0.0.0.0 as host",
"When this is required, Tauri sets the TAURI_DEV_PUBLIC_NETWORK_HOST_REQUIRED environment variable"
"When this is required, Tauri sets the TAURI_DEV_HOST environment variable"
);
url.set_host(Some(&ip)).unwrap();

Expand Down Expand Up @@ -312,7 +312,7 @@ fn run_dev(
.map(|device| !matches!(device.kind(), DeviceKind::Simulator))
.unwrap_or(false)
{
std::env::set_var("TAURI_DEV_PUBLIC_NETWORK_HOST_REQUIRED", "true");
std::env::set_var("TAURI_DEV_HOST", "true");
use_network_address_for_dev_url(&tauri_config, &mut options.config, options.force_ip_prompt)?;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { defineConfig } from "vite";
import { svelte } from "@sveltejs/vite-plugin-svelte";
import { internalIpV4Sync } from 'internal-ip'
import { internalIpV4Sync } from 'internal-ip';

const mobile = !!/android|ios/.exec(process.env.TAURI_ENV_PLATFORM);
const host = process.env.TAURI_DEV_HOST;

// https://vitejs.dev/config/
export default defineConfig({
Expand All @@ -13,10 +13,10 @@ export default defineConfig({
clearScreen: false,
// tauri expects a fixed port, fail if that port is not available
server: {
host: mobile ? "0.0.0.0" : false,
host: host ? "0.0.0.0" : false,
port: 1420,
strictPort: true,
hmr: mobile ? {
hmr: host ? {
protocol: 'ws',
host: internalIpV4Sync(),
port: 1421
Expand Down

0 comments on commit 3110b2e

Please sign in to comment.