Skip to content

Commit

Permalink
Fix Safari issue with 0.0.0.0 network resolution (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
timacdonald authored Sep 22, 2023
1 parent 6b28527 commit 2cf5b9d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export default function laravel(config: string|string[]|PluginConfig): [LaravelP
function resolveLaravelPlugin(pluginConfig: Required<PluginConfig>): LaravelPlugin {
let viteDevServerUrl: DevServerUrl
let resolvedConfig: ResolvedConfig
let userConfig: UserConfig

const defaultAliases: Record<string, string> = {
'@': '/resources/js',
Expand All @@ -124,7 +125,8 @@ function resolveLaravelPlugin(pluginConfig: Required<PluginConfig>): LaravelPlug
return {
name: 'laravel',
enforce: 'post',
config: (userConfig, { command, mode }) => {
config: (config, { command, mode }) => {
userConfig = config
const ssr = !! userConfig.build?.ssr
const env = loadEnv(mode, userConfig.envDir || process.cwd(), '')
const assetUrl = env.ASSET_URL ?? ''
Expand Down Expand Up @@ -202,7 +204,7 @@ function resolveLaravelPlugin(pluginConfig: Required<PluginConfig>): LaravelPlug

const isAddressInfo = (x: string|AddressInfo|null|undefined): x is AddressInfo => typeof x === 'object'
if (isAddressInfo(address)) {
viteDevServerUrl = resolveDevServerUrl(address, server.config)
viteDevServerUrl = resolveDevServerUrl(address, server.config, userConfig)
fs.writeFileSync(pluginConfig.hotFile, viteDevServerUrl)

setTimeout(() => {
Expand Down Expand Up @@ -406,16 +408,17 @@ function resolveFullReloadConfig({ refresh: config }: Required<PluginConfig>): P
/**
* Resolve the dev server URL from the server address and configuration.
*/
function resolveDevServerUrl(address: AddressInfo, config: ResolvedConfig): DevServerUrl {
function resolveDevServerUrl(address: AddressInfo, config: ResolvedConfig, userConfig: UserConfig): DevServerUrl {
const configHmrProtocol = typeof config.server.hmr === 'object' ? config.server.hmr.protocol : null
const clientProtocol = configHmrProtocol ? (configHmrProtocol === 'wss' ? 'https' : 'http') : null
const serverProtocol = config.server.https ? 'https' : 'http'
const protocol = clientProtocol ?? serverProtocol

const configHmrHost = typeof config.server.hmr === 'object' ? config.server.hmr.host : null
const configHost = typeof config.server.host === 'string' ? config.server.host : null
const sailHost = process.env.LARAVEL_SAIL && ! userConfig.server?.host ? 'localhost' : null
const serverAddress = isIpv6(address) ? `[${address.address}]` : address.address
const host = configHmrHost ?? configHost ?? serverAddress
const host = configHmrHost ?? sailHost ?? configHost ?? serverAddress

const configHmrClientPort = typeof config.server.hmr === 'object' ? config.server.hmr.clientPort : null
const port = configHmrClientPort ?? address.port
Expand Down

0 comments on commit 2cf5b9d

Please sign in to comment.