我的环境
- 前窗,端口3000
- 后端-docker容器中的linux(ubuntu),端口5000
Vue(前端)配置. json
export default defineConfig({
plugins: [vue(), vueJsx()],
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
},
},
server: {
host: true,
port: 3000,
proxy: {
"/api": {
target: "http://127.0.0.1:5000",
changeOrigin: true,
secure: false,
rewrite: (path) => path.replace(/^\/api/, ""),
},
},
},
});
前端API调用代码
const response = await axios.post("http://127.0.0.1:5000/users/login?email=" + code);
后端(Nestjs)- main.ts
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.enableCors({
origin: 'http://localhost:3000',
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS',
credentials: true,
});
await app.listen(5000);
}
bootstrap();
我希望api调用转到后端localhost:5000
但是我得到一个404错误
当我尝试使用postman时,我得到了正常的返回,但是当我在Vue中使用axios发送相同的请求时,我得到了404未找到。
最让人无法理解的是,在目前的设置下,以前开发时通常都会要求。
我不知道怎么解决
请多多帮忙
当前正在编辑的存储库:https://github.com/PracticeofEno/ft_transcendence
谢谢
1条答案
按热度按时间9avjhtql1#
天啊...我发送POST消息..但API是GET消息