Express 没有在Heroku上显示的图像
我正在构建一个MERN应用程序,在该应用程序中,我将从express向客户端提供图像。 在开发中,一切都可以正常加载,但当我部署到heroku时,它不会显示图像。控制台显示 “加载资源失败:网络::错误\u连接\u被拒绝” ImageSlider.jsExpress 没有在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
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%" }}
/>