reactjs - 使用 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)
解决方案
推荐阅读
- file - 如何根据提供的包含文件名的文件在 for 循环中打开多个可写文件
- testing - 如何在 cypress 中继续写入同一个 JSON 文件?
- android - 即使有很多 RecyclerView 也只显示一项
- reactjs - 如果我单击链接以加载不同的模型,模型会显示然后消失。看起来像材料/组件问题
- c++ - 遍历向量图并在c ++中跨列获取最大值
- python - 不同 .yaml 文件格式的 pyyaml 语法差异
- javascript - Odoo12ce 对象在 setinterval 函数内部无法识别
- html - 无法从首页删除页眉?
- c# - 带有参数的服务的单例
- parquet - 使用 pyarrow 的 Python 错误 - ArrowNotImplementedError:未构建对编解码器“snappy”的支持