Skip to content

Commit

Permalink
fix(ipx): allow overriding baseURL regardless of router base (#484)
Browse files Browse the repository at this point in the history
Co-authored-by: Pooya Parsa <pyapar@gmail.com>
  • Loading branch information
jeanmatthieud and pi0 authored Jun 21, 2022
1 parent fc7e3d5 commit 2720956
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/runtime/providers/ipx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const operationsGenerator = createOperationsGenerator({
formatter: (key, val) => encodeParam(key) + '_' + encodeParam(val)
})

export const getImage: ProviderGetImage = (src, { modifiers = {}, baseURL = '/_ipx' } = {}, { nuxtContext: { base: nuxtBase = '/' } = {} }) => {
export const getImage: ProviderGetImage = (src, { modifiers = {}, baseURL } = {}, ctx) => {
if (modifiers.width && modifiers.height) {
modifiers.resize = `${modifiers.width}x${modifiers.height}`
delete modifiers.width
Expand All @@ -25,8 +25,12 @@ export const getImage: ProviderGetImage = (src, { modifiers = {}, baseURL = '/_i

const params = operationsGenerator(modifiers) || '_'

if (!baseURL) {
baseURL = joinURL(ctx.nuxtContext.base || '/', '/_ipx')
}

return {
url: joinURL(nuxtBase, baseURL, params, encodePath(src))
url: joinURL(baseURL, params, encodePath(src))
}
}

Expand Down
1 change: 1 addition & 0 deletions src/types/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export interface ImageCTX {
isDev: boolean
isStatic: boolean
nuxtState?: any
base?: string
}
$img?: $Img
}
Expand Down

0 comments on commit 2720956

Please sign in to comment.