Skip to content

Commit

Permalink
fix: initialData fallback loop
Browse files Browse the repository at this point in the history
  • Loading branch information
mercs600 committed Feb 8, 2021
1 parent 19a28c2 commit 9ac31c3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export default {
api: {
baseURL: 'http://localhost:3000/api',
endpoints: {
initialData: '?type=834'
initialData: '/?type=834'
}
},
layouts: {},
Expand Down
2 changes: 1 addition & 1 deletion lib/templates/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class API {
}
) {
return this.$http
.get(`${params.path}/${this.options.endpoints.initialData}`)
.get(`${params.path}${this.options.endpoints.initialData}`)
.catch(error => {
logger.warn(`cant get the initial config ${this.options.baseURL}`)
logger.error(new Error(error))
Expand Down
15 changes: 12 additions & 3 deletions lib/templates/plugins/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import API from '~typo3/lib/api'
import { getLocaleCodePath } from '~typo3/lib/i18n'
export default function(context, options) {
const { store, $axios } = context
let initialDataRetried = false

const api = {
...new API(
store.state.typo3 && store.state.typo3.domain
Expand All @@ -22,9 +24,16 @@ export default function(context, options) {
error.config.url &&
error.config.url.includes(options.api.endpoints.initialData)
) {
return api.getInitialData({
path: getLocaleCodePath(context)
})
if (!initialDataRetried) {
initialDataRetried = true
return api.getInitialData({
path: getLocaleCodePath(context)
})
} else {
throw new Error(
`initialData fallback not available for ${error.config.baseURL}${error.config.url}`
)
}
}
})

Expand Down

0 comments on commit 9ac31c3

Please sign in to comment.