module.exports = {
async rewrites() {
return [
{ source: '/api/:path*', destination: 'http://localhost:3000/:path*' },
]
},
}
const axios = require('axios');
const apiClient = axios.create({
baseURL: 'http://localhost:3000',
withCredentials: true,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
});
export const fetchData = () => {
return apiClient.get('/api/data');
};
通过以上步骤的操作,可以成功地使用 next.config.js 中的重写规则来处理 Axios 或 Fetch 请求。