英文:
Why axios delete with interceptors doesnt work?
问题
我正在创建一个简单的删除请求,但我的后端路由从未被触发,我不知道我做错了什么。任何帮助都将很好!!
const instance = axios.create({
baseURL: 'http://13axxxxx.ngrok.io'
});
instance.interceptors.request.use(
async (config) => {
const token = await AsyncStorage.getItem("token");
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
return config;
},
(err) => {
return Promise.reject(err);
}
);
export default instance;
import BaseAPI from './BaseAPI';
const deleteAccount = () => {
return BaseAPI.delete('/delete_account');
}
在我的后端,这个路由从未被触发:
app.use(router.delete('delete_account', (req, res, next) => {
console.log("delete called")
}))
英文:
I am making a simple delete request but my backend route is never reached and I dont know what I am doing wrong. Any help would be great!!
const instance = axios.create({
baseURL: 'http://13axxxxx.ngrok.io'
});
instance.interceptors.request.use(
async (config) => {
const token = await AsyncStorage.getItem("token");
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
return config;
},
(err) => {
return Promise.reject(err);
}
);
export default instance;
import BaseAPI from './BaseAPI';
const delete = () => {
return BaseAPI.delete('/delete_account');
}
in my backend this route is never hit:
app.use(router.delete('delete_account', (req, res, next) => {
console.log("delete called")
}))
答案1
得分: 1
问题在于您错过了您的代码中起始的“/”:
router.delete("/…")
英文:
The issue here is that you’ve missed the starting “/“ in your
router.delete(“/…”)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论