Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Express 没有在Heroku上显示的图像_Express_Heroku_Static - Fatal编程技术网

Express 没有在Heroku上显示的图像

Express 没有在Heroku上显示的图像,express,heroku,static,Express,Heroku,Static,我正在构建一个MERN应用程序,在该应用程序中,我将从express向客户端提供图像。 在开发中,一切都可以正常加载,但当我部署到heroku时,它不会显示图像。控制台显示 “加载资源失败:网络::错误\u连接\u被拒绝” ImageSlider.js import React from "react"; import { Carousel } from "antd"; const ImageSlider = (p

我正在构建一个MERN应用程序,在该应用程序中,我将从express向客户端提供图像。 在开发中,一切都可以正常加载,但当我部署到heroku时,它不会显示图像。控制台显示 “加载资源失败:网络::错误\u连接\u被拒绝”

ImageSlider.js

  

    import React from "react";
    import { Carousel } from "antd";
    
    const ImageSlider = (props) => {
      return (
        <div>
          <Carousel autoplay>
            {props.images.map((image, index) => {
              return (
                <div key={index}>
                  <img
                    src={`http://localhost:5000/${image.filename}`}
                    alt={`product_image-${index}`}
                    style={{ height: "150px", width: "100%" }}
                  />
                </div>
              );
            })}
          </Carousel>
        </div>
      );
    };
    
    export default ImageSlider;
      

我提供上传文件夹中的静态文件 我的文件夹结构是
AppName/

  /client 
  /server/uploads
服务器和mongo正在heroku上运行,因为我可以使用凭据登录


非常感谢您的帮助。

您似乎正在尝试从硬编码的URL(
http://localhost:5000
):


非常感谢,就这样!我以为heroku会自动识别localhost:5000作为服务器文件夹。我现在觉得自己很愚蠢。谢谢你的快速回复!
  /client 
  /server/uploads
<img
   src={`http://localhost:5000/${image.filename}`}
   alt={`product_image-${index}`}
   style={{ height: "150px", width: "100%" }}
/>
<img
   src={`/${image.filename}`}
   alt={`product_image-${index}`}
   style={{ height: "150px", width: "100%" }}
/>