Skip to content

Commit

Permalink
Include base in hotFile without modifying server.origin replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
danielztolnai committed May 16, 2024
1 parent 908b775 commit 6ce66ab
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ interface LaravelPlugin extends Plugin {
config: (config: UserConfig, env: ConfigEnv) => UserConfig
}

type DevServerUrl = `${'http'|'https'}://${string}:${number}${string}`
type DevServerUrl = `${'http'|'https'}://${string}:${number}`

let exitHandlersBound = false

Expand Down Expand Up @@ -204,7 +204,9 @@ function resolveLaravelPlugin(pluginConfig: Required<PluginConfig>): LaravelPlug
const isAddressInfo = (x: string|AddressInfo|null|undefined): x is AddressInfo => typeof x === 'object'
if (isAddressInfo(address)) {
viteDevServerUrl = userConfig.server?.origin ? userConfig.server.origin as DevServerUrl : resolveDevServerUrl(address, server.config, userConfig)
fs.writeFileSync(pluginConfig.hotFile, viteDevServerUrl)

const base = server.config.base.replace(/\/$/, '')
fs.writeFileSync(pluginConfig.hotFile, `${viteDevServerUrl}${base}`)

setTimeout(() => {
server.config.logger.info(`\n ${colors.red(`${colors.bold('LARAVEL')} ${laravelVersion()}`)} ${colors.dim('plugin')} ${colors.bold(`v${pluginVersion()}`)}`)
Expand Down Expand Up @@ -431,9 +433,8 @@ function resolveDevServerUrl(address: AddressInfo, config: ResolvedConfig, userC

const configHmrClientPort = typeof config.server.hmr === 'object' ? config.server.hmr.clientPort : null
const port = configHmrClientPort ?? address.port
const base = config.base.replace(/\/$/, '')

return `${protocol}://${host}:${port}${base}`
return `${protocol}://${host}:${port}`
}

function isIpv6(address: AddressInfo): boolean {
Expand Down

0 comments on commit 6ce66ab

Please sign in to comment.