在ReactJS项目中单独服务NodeJS服务器

时间:2020-04-20 14:00:37

标签: javascript node.js reactjs express proxy-server

我正在redux动作中发出API请求。该API请求由于CORS问题而被阻止。为了解决这个问题,我在同一项目上制作了一个代理Express NodeJS服务器,该服务器侦听不同的端口。 在我的本地主机上,这对开发很有用。但是在生产环境中(部署在Heroku上),我无法提供代理服务器。

部分问题是我不确定生产中为代理服务器提供服务的端口,以及与React App不同的服务方式

我的API调用

Insert snippet

我的Express NodeJS服务器

 axios.get(`/api/item-info`, {
            params: {
              productId: productId,
              variantId: variantId
            }
          })
          .then(response => response.data)
          .then(data =>
            dispatch(checkItemInventoryQuantity(parseInt(data.variant.inventory_quantity)))
          )
          .catch(error => console.log(error));

0 个答案:

没有答案