поэтому я установил перехватчик для axios, и я добавляю пользовательский заголовок к моим запросам.Тем не менее, когда я проверяю мой код сервера.Заголовок принимается только в запросе OPTIONS
.
class ChainInterceptors {
constructor(config) {
this.cleanConfig = { ...config };
}
build() {
return this.cleanConfig;
}
}
export class ReqInterceptor extends ChainInterceptors {
constructor(config) {
super(config);
}
setLog() {
this.cleanConfig.headers['Respond-By'] = // some value;
return this;
}
}
И я реализую его следующим образом:
export const request = {
init() {
const token = getItem('token');
const request = axios.create({
httpsAgent: new https.Agent({ keepAlive: true }),
baseURL: LOCAL_URL,
headers: {
authorization: `bearer ${token}`,
'Content-Type': 'application/json',
},
});
this.attachInterceptor(request);
return request;
},
attachInterceptor(request) {
request.interceptors.request.use(config => {
return new ReqInterceptor(config).setLog().build();
});
request.interceptors.response.use(
response => {
// response interceptors
},
error => {
// Do something with response error
return Promise.reject(error);
}
);
},
get() {
return this.init().get.apply(null, arguments);
},
// and other methods...
};
Как я уже говорил выше, заголовок Respond-By
присутствует только в моем запросе OPTIONS
.Ваше руководство очень ценится.