Skip to content

Commit

Permalink
Don't send the Base URL header on unrelated Axios requests
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalbaljet committed Oct 31, 2024
1 parent c9d6ed2 commit 370a734
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion react/src/ModalRoot.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ export const ModalStackProvider = ({ children }) => {
'X-Inertia-Partial-Data': keys.join(','),
'X-InertiaUI-Modal': true,
'X-InertiaUI-Modal-Use-Router': 0,
'X-InertiaUI-Modal-Base-Url': baseUrl,
},
}).then((response) => {
this.updateProps(response.data.props)
Expand Down Expand Up @@ -308,6 +309,7 @@ export const ModalStackProvider = ({ children }) => {
'X-Inertia-Version': pageVersion,
'X-InertiaUI-Modal': true,
'X-InertiaUI-Modal-Use-Router': useInertiaRouter ? 1 : 0,
'X-InertiaUI-Modal-Base-Url': baseUrl,
}

if (useInertiaRouter) {
Expand Down Expand Up @@ -489,7 +491,9 @@ export const ModalRoot = ({ children }) => {
const axiosRequestInterceptor = (config) => {
// A Modal is opened on top of a base route, so we need to pass this base route
// so it can redirect back with the back() helper method...
config.headers['X-InertiaUI-Modal-Base-Url'] = baseUrl
if (localStackCopy.length) {
config.headers['X-InertiaUI-Modal-Base-Url'] = baseUrl
}
return config
}

Expand Down
4 changes: 3 additions & 1 deletion vue/src/ModalRoot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ onUnmounted(
const axiosRequestInterceptor = (config) => {
// A Modal is opened on top of a base route, so we need to pass this base route
// so it can redirect back with the back() helper method...
config.headers['X-InertiaUI-Modal-Base-Url'] = modalStack.getBaseUrl()
if (modalStack.stack.value.length) {
config.headers['X-InertiaUI-Modal-Base-Url'] = modalStack.getBaseUrl()
}
return config
}
Expand Down
2 changes: 2 additions & 0 deletions vue/src/modalStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class Modal {
'X-Inertia-Partial-Data': keys.join(','),
'X-InertiaUI-Modal': true,
'X-InertiaUI-Modal-Use-Router': 0,
'X-InertiaUI-Modal-Base-Url': baseUrl.value,
},
}).then((response) => {
this.updateProps(response.data.props)
Expand Down Expand Up @@ -266,6 +267,7 @@ function visit(
'X-Inertia-Version': usePage().version,
'X-InertiaUI-Modal': true,
'X-InertiaUI-Modal-Use-Router': useInertiaRouter ? 1 : 0,
'X-InertiaUI-Modal-Base-Url': baseUrl.value,
}

if (useInertiaRouter) {
Expand Down
4 changes: 4 additions & 0 deletions vue/tests/modalStack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ describe('modalStack', () => {
'X-Inertia-Partial-Data': 'test,another',
'X-InertiaUI-Modal': true,
'X-InertiaUI-Modal-Use-Router': 0,
'X-InertiaUI-Modal-Base-Url': null,
},
})

Expand Down Expand Up @@ -185,6 +186,7 @@ describe('modalStack', () => {
'X-Inertia-Partial-Data': 'test',
'X-InertiaUI-Modal': true,
'X-InertiaUI-Modal-Use-Router': 0,
'X-InertiaUI-Modal-Base-Url': null,
},
})

Expand Down Expand Up @@ -216,6 +218,7 @@ describe('modalStack', () => {
'X-Inertia-Partial-Data': 'test,third',
'X-InertiaUI-Modal': true,
'X-InertiaUI-Modal-Use-Router': 0,
'X-InertiaUI-Modal-Base-Url': null,
},
})

Expand Down Expand Up @@ -267,6 +270,7 @@ describe('modalStack', () => {
'X-Inertia-Version': '1.0',
'X-InertiaUI-Modal': true,
'X-InertiaUI-Modal-Use-Router': 0,
'X-InertiaUI-Modal-Base-Url': '',
},
})

Expand Down

0 comments on commit 370a734

Please sign in to comment.