首页 > 解决方案 > 使用 http-proxy-middleware 模块反应手动代理不起作用

问题描述

我的节点服务器端口是8000 我在 REACT 文件夹的 src 中添加 setupProxy.js 文件,下面是 setupProxy.js 代码

const { createProxyMiddleware } = require('http-proxy-middleware');

module.exports = (app) => {
  app.use(
    '/api',
    createProxyMiddleware({
      target: 'http://localhost:8000',
      changeOrigin: true,
    })
  );
};

我使用 fetch 在 REACT 中调用 API

const requestOptions = {
                method: 'POST',
                headers: { 'Content-Type': 'application/json' },
                body: JSON.stringify({ url: 'hamza' })
            };
const getStores = await fetch('/users/stores/get-single-stores', requestOptions)

这是后端路由器

router.get('/users/stores/get-single-stores/', middleware.VerifyByLinkRegister, () => { });

我得到了以下错误,我不知道为什么会发生 http://localhost:3000/users/stores/get-single-stores 404 (Not Found)

标签: reactjsproxy

解决方案


推荐阅读