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
…296)

* Include base in hotFile without modifying server.origin replacement

* Formatting

---------

Co-authored-by: Tim MacDonald <[email protected]>
  • Loading branch information
danielztolnai and timacdonald authored May 17, 2024
1 parent 908b775 commit 5162674
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 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,8 @@ 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)

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

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 +432,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 5162674

Please sign in to comment.