0

I added "proxy": "http://localhost:3006/api" to my package.json and now I'm unable to route to my images. The proxy is being applied to the <img> tag. Is there a way to disable the proxy on certain calls? If I wanted to use s3 I would run into the same problem. If I remove the proxy then I run into all kind of CORs and header issues.

enter image description here

This is the same error but I don't find the solution.

<ListItemAvatar>
    <Avatar alt={otherUser.username} src={otherUser.avatar} component={Link} to={`/messages/${chat._id}`} />
</ListItemAvatar>

UPDATE: I've updated the proxy as shown here.

Images are coming through the same as before. Can I fix the issue in setupProxy.js?

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

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

1 回答 1

1

你没有提到你为什么想要代理,但我假设你的 api 调用在提到的代理 url 下,但是你的图像在你的前端 repo 中。

这不是代理的目的,它非常简单,因为所有获取然后都被路由到提供的 url。图像也被提取。

我建议查看您的开发服务器并通过那里进行代理。

如果您使用 webpack 检查:他们的代理 webpack-dev-server

于 2020-10-19T13:21:18.440 回答