Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/url for origin #12621

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions shell/utils/axios.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const extendAxiosInstance = (axios) => {
}
};

const createAxiosInstance = (axiosOptions) => {
const createAxiosInstance = (axiosOptions, ctx) => {
// Create new axios instance
const axios = Axios.create(axiosOptions);

Expand All @@ -70,12 +70,38 @@ const createAxiosInstance = (axiosOptions) => {

setupProgress(axios);
axiosRetry(axios, { retries: 0 });
interceptApiRequest(axios, ctx.$config);

return axios;
};

/**
* Intercepts requests to rewrite URLs. This is useful intercepting any direct
* API calls when running dashboard with a proxy server.
*
* NOTE: This is currently used for running Dashboard in Rancher Desktop.
* @param {*} axios The axios instance to modify
*/
const interceptApiRequest = (axios, config) => {
if (config.rancherEnv !== 'desktop') {
return;
}

axios.interceptors.request.use((config) => {
if (config.url.includes(':9443')) {
config.url = config.url
.replace('https://', 'http://')
.replace(':9443', ':6120');
}

return config;
}, (error) => {
return Promise.reject(error);
});
};

const setupProgress = (axios) => {
// A noop loading inteterface for when $loading is not yet ready
// A noop loading interface for when $loading is not yet ready
const noopLoading = {
finish: () => { },
start: () => { },
Expand Down Expand Up @@ -163,7 +189,7 @@ export default (ctx, inject) => {
headers
};

const axios = createAxiosInstance(axiosOptions);
const axios = createAxiosInstance(axiosOptions, ctx);

// Inject axios to the context as $axios
ctx.$axios = axios;
Expand Down
Loading