Reactjs 在axios配置中找不到jhipster react标头内容
我对杰普斯特是新来的,也是新来的。我一直在检查react代码结构,发现它的结构非常好。但有一件事我找不到:头内容(如access_token、application/json、x-xsrf-token、host)在哪里配置 axios配置有拦截器:Reactjs 在axios配置中找不到jhipster react标头内容,reactjs,axios,jhipster,jhipster-gateway,Reactjs,Axios,Jhipster,Jhipster Gateway,我对杰普斯特是新来的,也是新来的。我一直在检查react代码结构,发现它的结构非常好。但有一件事我找不到:头内容(如access_token、application/json、x-xsrf-token、host)在哪里配置 axios配置有拦截器: import axios from 'axios'; import { getBasePath, Storage } from 'react-jhipster'; import { SERVER_API_URL } from 'app/config
import axios from 'axios';
import { getBasePath, Storage } from 'react-jhipster';
import { SERVER_API_URL } from 'app/config/constants';
const TIMEOUT = 1 * 60 * 1000;
axios.defaults.timeout = TIMEOUT;
axios.defaults.baseURL = SERVER_API_URL;
const setupAxiosInterceptors = onUnauthenticated => {
const onRequestSuccess = config => {
return config;
};
const onResponseSuccess = response => response;
const onResponseError = err => {
const status = err.status || (err.response ? err.response.status : 0);
if (status === 403 || status === 401) {
onUnauthenticated();
}
return Promise.reject(err);
};
axios.interceptors.request.use(onRequestSuccess);
axios.interceptors.response.use(onResponseSuccess, onResponseError);
};
export default setupAxiosInterceptors;
这是一个示例reducer文件(authentication.ts):
我没有看到任何axios.headers.access\u token=“my token”
,但在发送请求时设置了头值。
你能告诉我它是怎么工作的吗?标题内容在哪里
export const getSession: () => void = () => async (dispatch, getState) => {
await dispatch({
type: ACTION_TYPES.GET_SESSION,
payload: axios.get('services/uaa/api/account'),
});
const { account } = getState().authentication;
if (account && account.langKey) {
const langKey = Storage.session.get('locale', account.langKey);
await dispatch(setLocale(langKey));
}
};
export const login: (username: string, password: string, rememberMe?: boolean) => void = (username, password, rememberMe = false) => async (
dispatch,
getState
) => {
const result = await dispatch({
type: ACTION_TYPES.LOGIN,
payload: axios.post('auth/login', { username, password }),
});
await dispatch(getSession());
};
export const logout: () => void = () => async dispatch => {
await dispatch({
type: ACTION_TYPES.LOGOUT,
payload: axios.post('auth/logout', {}),
});
// fetch new csrf token
dispatch(getSession());
};
export const clearAuthentication = messageKey => (dispatch, getState) => {
dispatch(displayAuthError(messageKey));
dispatch({
type: ACTION_TYPES.CLEAR_AUTH,
});
};